Monday, November 09, 2009 2:15 AM,




Now that program 3 is history, I thought I would share some email that came in 
today from a student who admitted that it was not critical to program 3, but 
wanted me to answer when I had time.  To be fair to him, he later sent me 
email telling me understood that he was incorrect.

Here is his email and my response:



	 Dr. Patt,
	
	 This question does not actually pertain to the program, so if you have 
	 more pressing matters, feel free to address this at a later date.  I 
	 had a question concerning the .stringz pseudo-op.  I would assume that 
	 you could store the string "000", effectively setting 4 lines of code 
	 to x0000, correct?  If so, why would you not do this instead of the 
	 .blkw 4 command?  It would seem that clearing and saving 4 lines of 
	 code would be superior to just saving 4 lines.
	 
	 Thank you,
	 <<name withheld to protect the student looking for ways to get rid of 
	 .BLKW>>



Actually, .STRINGZ "000" would do, for all practical purposes, what .BLKW 4 
does, so the student is right - we could get rid of .BLKW if we wanted to.
But it would not do what the student initially thought it would do.  I will 
explain.

First, the purpose of .BLKW 4 is to reserve 4 words of memory for later use.
That is, we do not care what gets assembled into those four locations, because 
they will get overwritten either by the program or some other module BEFORE 
they ever get read.  .STRINGZ "000" will, in fact, also get assembled into 
four locations of memory.  If we overwrite the four words assembled there 
before reading them, then the effect of .BLKW 4 and .STRINGZ "000" will be the 
same.

However, the student is wrong if he thinks .STRINGZ "000" will get assembled 
into four words of memory, each containing x0000.  Do you see why?

Question for you: What will the four words of memory contain as a result of 
assembling .STRINGZ "000" ?

By the way, .BLKW 4 does not specify that the contents of those four words of 
reserved memory contain x0000.  The LC-3 Assembly Language only specifies that 
four words will be reserved, and says nothing about what their initial 
contents will be.  One LC-3 Assembler could choose to initialize the four 
locations to x0000, but another could initialize them to xFFFF, and a third 
could initialize them to xF0F0.  The Assembly Language only specifies that the 
locations are reserved in the .obj file that is generated by the assembler.

Hope you successfuly completed program 3.  Program 4 will be even more fun.
See you in class tomorrow.

Yale Patt