lw
requires the address you download to be word aligned (i.e. the address must be a multiple of 4).
So, let's say that you have this array located at 0x1000:
array: .byte 0,1,2,3
And you want to load the second byte ( 1
), which is located at 0x1001, which does not align by word. This obviously won't work if you didn't lw
from address 0x1000 and then made some changes and ANDing to get the byte you wanted, which would be a real problem as a programmer.
Or say that you want to load 0
, which is located at the address aligned by word, and compare it with some value. Thus, you execute lw
from address 0x1000, but now your target register will contain 0x00010203
or 0x03020100
(depending on the entity), and not just 0
. Therefore, before performing the comparison, you will have to bitwise AND retrieve your byte, which you need.
As I am sure, you can see that it would be very inconvenient to take these additional steps whenever you want to process individual bytes of data, which is a fairly common operation in most programs.
source share