Monday, October 26, 2009 1:00 AM,



A student writes:



	 Dr. Patt,
	       Okay first, I have loaded each x3200 value into the x4000 
	 location. Now I am taking two numbers, comparing them, and wanting to 
	 store them into the correct location. So, for example, I have grade 55 
	 in x4000 and 68 in x4001 so I want to store 55 in x4001 and 68 in 
	 x4000. I know one of the TA's told me to store the numbers so they are 
	 at the different location pointer, but then I do not know how to get 
	 that value back into x4000 and x4001 from the registers. Hopefully 
	 this is enough information for you.
	
	 <<name withheld to protect the student who has trouble swapping two 
	 values>>




You have  M[x4000]= 55 and M[x4001]= 68, and you want to end up with M[x4000]= 
68 and M[x4001]= 55.  That is, you want to swap the values in x4000 and x4001.  
And you have two registers acting as pointers, 
say: R1=x4000 and R2=x4001.   

Rather than answer the question, perhaps I can help you figure it out for 
yourself.

So, Question 1: What instruction will put 68 into M[x4000]?
Question 2: What do I have to do to 68 before I can execute that instruction?
Question 3: What will happen to the 55 if I put 68 into M[x4000]?
Question 4: What do I have to do to make sure the answer to Question 2 3 does 
not happen?

Hint: To do what you want will take four LC-3 instructions.

Can you take it from there?  If not, where are you stuck?

Good luck finishing program 2.

Yale Patt