Friday, December 11, 2009 2:41 AM,



A student writes:



	 Quick question for you, Dr. Patt. I was wondering if the condition 
	 codes are set when the PC is stored in R7 during a JSR or TRAP 
	 instruction. The book says that they are set every time a GPR is 
	 written to, but problem 9 of the 2006 final exam has a branch being 
	 taken on the condition codes set by clearing R0, when the PC value is 
	 written to R7 after the AND R0,R0,#0. Unless, of course, I am mistaken 
	 in my translation of hex to binary instructions on the 2006 exam.
	 
	 Thanks,
	 <<name withheld to protect the student who found an error in the 
	 book>>



Actually, if the book says the cc are set every time a gpr is written, then 
the book is incorrect.  If the student sending me this email would please send 
me the page and line number where it says this, I will read it, and make any 
necessary corrections.

What is true is that cc are set as a result of any load or operate instruction 
loading a gpr.  And, in fact, if you look in Appendix A and also if you look 
at the state machine, you will see that only ADD, AND, NOT, LD, LDI, LDR, and 
LEA set condition codes.  

Yes, the TRAP instruction does load R7 with the contents of the PC, but it 
does not set cc.  The reason is actually quite simple: Condition codes should 
reflect whether the last VALUE dealt with is negative, zero, or positive.  
Registers get written with values computed in the alu and also with values 
loaded from memory.  In the case of TRAP and JSR, R7 is loaded with an 
address.  Got it?

If you are interested (and this is not something that is important for the 
exam next Tuesday), reading the above explanation, you should ask yourself:
Then why does LEA set cc.  Isn't it an address that is being loaded into a 
register?  Answer: yes, based on my explanation above, LEA should not set cc.  
Therefore, in the 3rd edition of the book, LEA will not set cc.

Good luck on the final exam.

Yale Patt

 
> 
>