0

While trying to make an assembler for SIC, I thought of these questions.

LABEL BYTE X'AB'

Here the generated object code would be AB. So the object code might look something like this as an example.

001045 4C1046 AB 001045

Here I have used space to differentiate the code, but the object code would look like this.

0010454C1046AB001045

So while executing the object code how does the loader find out that the AB is indeed a constant not part of any mnemonic object code?

I have the same question for WORD too, as the length of a WORD might be 3 bytes but how do the loader differentiate between constant and mnemonic code.

Any clarification would be appreciated.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    Processors cannot tell the difference between instructions and data, which is why you as a programmer must avoid placing data in any execution path (e.g. between two instructions, unless the first instruction is an unconditional jump). – Michael Sep 11 '16 at 20:27
  • Then suppose I made a data segment where I have not put anything of the execution path. Even then the code is executed and some data is called using label, how do the processor find out where that certain data ends? Do they always take 3 bytes or 1 byte of data (in SIC) according to the mnemonic? Like for `LDA NUM` it will look for 3 bytes of data starting from the address of `NUM`, and for `LDCH NUM` it will look for 1 byte of data. Like this? @Michael – smashingpumpkin Sep 11 '16 at 20:35
  • I'm not familiar with this particular instruction set architecture, but typically when you read from memory you read as much data as the size of the destination operand, and when you write to memory you write as much as the size of the source operand. Some processors also have instructions for reads/writes of a certain size (load byte, load halfword, load word, etc). – Michael Sep 11 '16 at 20:40

0 Answers0