Sun, 10 Feb 2013, 17:35




A student writes:

> Dr. Patt,
>
> I had a quick question regarding Lab 2 and the LDB instruction. After we
> have sign-extended the last 6 bits and then added that result to the
> contents in the base register, do we always assume that address will be
> even? Or do we need to take into account if its odd or even to get the
> correct byte from memory? (MEMORY[][0] or MEMORY[][1])
> 
> Thanks!
> 
> <<name withheld to protect the student who is unclear on odd addresses>>

Apparently, I have not made clear what the LDB instruction does.  LC-3b
memory is byte addressable. That means in every memory location, whether
the location has an odd address or an even address, there is stored 8 bits
of information.  LDB gets those 8 bits from the location and loads them into
the specified destination register.  Since we want to be able to load a
byte from any memory location, the address we are loading from must be able
to be odd or even.

And, in the interest of pre-empting questions about LDW, if we are loading
16 bits, the address must be even since our convention is that a word of
memory consists of the contents of A and the contents of A+1, where A is
an even address.  Not all ISAs have that restriction, but the LC-3b does.

So, for example, if you try to do a LDW from an odd address (address x4001,
for example), the computer will barf and terminate your program with the 
run-time error known as "unaligned access fault."  The 16 bits contained in
locations x4001 and x4002 would require an unaligned access.  We will see
why we do not allow unaligned accesses in due course (maybe before the end of 
next week, certainly before Spring break).  In the meantime, very simple: 
LDB can load a byte from any location in memory, LDW requires that the 
address A must be even in order to get the aligned contents of locations 
A and A+1.   

OK?

Good luck finishing lab 2 tonight.

Yale Patt