I have a question about the offset units used in MIPS32 instructions. I just noticed that memory access instructions like lw $t0, offset($s1)
has offset
of unit byte, while branching instructions like beq $r1, $r2, L1
and jump j SOMEWHERE
both have unit word.
IIRC, MIPS requires that every data/instructions should be stored aligned in memory at address of multiple of 4, i.e. 0x0, 0x4, 0x8, ... etc
. If this is true, then why not let offset
in lw/sw
of unit word, so the range is larger? Is this because of lb/sb
which uses a byte unit? So Special cases aren't special enough to break the rules ["] Good design demands good compromises.[."] applies here?
I also wonder what will happen if I use lw
to load data that is at address that is not a multiple of 4?