Sat, 24 September 2016, 18:43

A student writes:

> Dear Dr. Patt,
> I was finishing up the Lab 2 when I ran into a problem with STW and LDW
> Why are we left shifting the offset?
> For example, if the instruction reads STW R4, R1, #10 why are we doing
> MEMORY[R1 + 20] \<-- R4?
> and it is the same thing with LDW. So if I understand correctly, if R1 has
> the value 0x000 we would be storing R4 into memory location 0x0014??
> Regards,
> <<name withheld to protect the student who doesn't know why we left shift>>

You are correct, both LDW and STW form the memory address by adding an offset
to a base register.  The size of the offset determines the range of memory
locations plus and minus the contents of the Base Register that we can access.
With six bits of offset that could mean up to +31 or down to -32 locations.
Since we are loading and storing words, and since memory does not support
unaligned accesses, we can assume the Base Register contains an even number.
Since we would never  want to end up with an odd offset, we are wasting half
of the 64 values in the offset field.  So, by left shifting before we add to
the Base Register, the offset allows us to specify up to +31 WORDS or down to
-32 WORDS.  ...or, said another way, up to +62 locations or down to -64
locations.  That is, we double the range at no cost.

Yes, if R1 contained the value x0000, and the offset contained the value #10,
we would access memory location x0014 (i.e., #20).

Good luck with the rest of Lab 2.

Yale Patt