手动执行 lb MIPS 指令

Execute lb MIPS instruction by hand

我正在手动执行 MIPS 指令,但我并不真正理解它是如何工作的。在下面给出的示例中,$t0 中的内容从 0x00001117 变为 0x00000080。我不明白为什么。任何帮助都会很棒。

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

这假定了小端内存布局。

$s0 的值为 0x10010010,因此 5($s0) 指的是地址 0x10010015.

处的值

以字节形式查看时,您的内存内容如下所示:

            +0 +1 +2 +3
-----------------------
0x10010010: 04 00 40 00
0x10010014: 08 80 40 00
...

如你所见,0x10010015处的字节是0x80。由于 lbu 将加载值零扩展为 32 位,因此 $t0 的高 24 位被清除。