I am working on executing MIPS instructions by hand and I am not really understanding how it works. In the example given below, the contents in $t0 changes from 0x00001117 to 0x00000080. I do not understand why though. Any help would be great.
lbu $t0, 5($s0)
lbu (i-type, load byte unsigned) 
Registers before                Instruction Registers after
Register       Contents            Register       Contents
$t0         0x00001117          $t0         0x00000080
$s0         0x10010010          $s0         0x10010010
$pc         0x0040008c          $pc         0x00400090
Memory before                   Memory After
Location    Contents            Location    Contents
0x10010010  0x00400004          0x10010010  0x00400004
0x10010014  0x00408008          0x10010014  0x00408008
0x10010018  0x0040001c          0x10010018  0x0040001c
This assumes a little-endian memory layout.
$s0 has the value 0x10010010, so 5($s0) refers to the value at address 0x10010015.
Your memory contents when viewed as bytes looks like this:
            +0 +1 +2 +3
-----------------------
0x10010010: 04 00 40 00
0x10010014: 08 80 40 00
...
As you can see, the byte at 0x10010015 is 0x80. And since lbu zero-extends the loaded value to 32 bits, the upper 24 bits of $t0 are cleared.
 Michael
 MichaelUser contributions licensed under CC BY-SA 3.0