Administrator
|
There are some advantages to keeping them separate, such as being able to print out a more meaningful symbol table if you want, but that isn't necessary.
Once a number is associated with a name all the assembler has to do is replace the name with that number in A-type instructions.
Consider the following:
@18
D=D+A
@18
D=D+M
@18
D;JGT
The most likely meaning of those three A-type instructions is very different. In the first one, 18 is just a value being added to the current contents of D. In the second, 18 is a RAM address where a value is stored that is being added to the current contents of D. In the third, 18 is a ROM address where execution will jump to if the current value of D is strictly positive.
But this code would be identical to
@18
D=D+A
@my_varname
D=D+M
@MY_GOTO_LABEL
D;JGT
if the pseudo-instruction
(MY_GOTO_LABEL)
were located above the instruction that will get stored in ROM[18] and if @my_varname was the third variable name encountered by the assembler on its second pass.
Both would be in the symbol table and both would be associated with the value 18. So what. When the assembler comes across either, it looks in the symbol table for that name and replaces it with the associated value.
Yes, that does mean that you could swap them, or use one of them for all three A-type instructions, including the literal constant 18 in the first line, and you will generate the exact same code. That would not be very smart from a code readability or maintainability standpoint, but it would still produce the exact same code.
|