Sat, 29 Oct 2011, 19:55


A student is working Exam 2 from Fall, 2009, and writes:

> Dr Patt,
> 
> I have a quick question regarding problem 2 part (a) on Exam 2 in 2009.
> Basically, I can't work out why the program stops when R2 points to x8000.
> I can't find any reference to x8000 in the program.   Any explanation would
> be much appreciated.
> 
> Thank you, 
> <<name withheld to protect the student who wonders where x8000 comes from>>

I think it is best to not deprive you of the joy of figuring out (a) where
x8000 came from and (b) why it is relevant to the matter at hand.

However, I will try to point you in the right direction.

Any time you are asked what a program does, it is a good idea to follow
the execution of the program for enough instructions until you understand
what is going on.  I won't carry this all the way for you, but I will get
you started.

So, then:

The first instruction is LEA R2, ONE.  What does that do?
Answer: It loads the address x4006 into R2.

The second instruction is AND R5,R5, #0.  What does it do?
Answer: We have seen this instruction enough times that I will leave it
for you to answer for yourself.

The third instruction to be executed is ADD R2,R2,#2.  What does it do?

The idea is to continue doing this until you see what the program is doing.
If you will do that, you will see (a) where x8000 comes from and (b) why 
it matters.

Good luck on the second midterm.

Yale Patt