Saturday, December 05, 2009 5:45 PM,



A student writes:



	 Dr. Patt, one quick question concerning the assembly proccess in the 
	 LC3 assembler.
	 
	 i remember you mentioning in class that all that happens in pass
	 1 is the generation of the symbol table. however whenever i try to 
	 assmeble my progrmam on the lc3,  errors for improper commands come up 
	 under pass 1. for ex:
	 .
	 
	 ADDD  R1, R1, #0
	 .
	 
	 would come up with the error:
	 Starting Pass 1.....
	 Line 4: Unrecognized opcode or syntax error at or before R1
	 
	 
	 why is that, does pass one also check for the syntax of the commands?
	
	 <<name withheld to protect the student who found an interesting 
	 example>>
 


Looks like it does!  Good for you for recognizing it.
 
Incidentally, this points one more difference between natural sciences (like 
physics) and man-made sciences (like computers).  In man-made sciences, we get 
to create "nature," in this case the computer and the software running on it.
 
If I were writing the assembler, I would do as I said, use pass 1 to just 
create the symbol table which is all you really need in order to be able to 
complete the job with pass 2.  Based on your error message, clearly the TA who 
wrote the Assembler a long time ago decided he wanted to have pass 1 do more, 
and had it check for things like ADD is spelled ADDD.  

[By the way, did you catch the subtlety: the Assembler did not say that ADDD 
was an unrecognized opcode.  It said EITHER it was an unrecognized opcode, OR 
it was a label and an opcode was missing because R1 can not be an opcode.
 
Aha!  I now see why my TA wanted to do this on pass 1.  He was not checking 
all syntax, he was generating the symbol table (as I said), but in this line, 
he could not tell whether ADDD was a label or a misspelled opcode.  Therefore 
the error message.
 
So, he was doing what I would do in pass 1, but he also found something wrong 
with the program in doing so, and felt it would be good to let the programmer 
know that.  Therefore, his error message.  Good for him!  

In summary, yes Pass 1 is generating the symbol table and the assembler cannot 
tell what to do here vis-a-vis the symbol table.  So, it spits out an error 
message.
 
So, I was right in this case.  However, my original point is still important.  
If someone wants to add additional functions in pass 1, he or she is free to 
do it.  And, my original statement about pass 1 ONLY generating the symbol 
table should have been couched less arrogantly: If I were writing a 2 pass 
assembler, pass 1 would just generate the symbol table.
 
OK?

Good luck on the final.

Yale Patt