MIPS-32 链接器如何转换 lw 和 sw 地址?
How does a MIPS-32 linker convert lw and sw addresses?
我正在阅读 Computer Organization and Design 的第 2.12 章,试图理解 MIPS-32 链接器的逻辑。我了解链接两个目标文件和绝对引用链接的概念。我不明白的是下面引用的段落解释了计算绝对地址的逻辑。
The load and store addresses are harder because they are relative to a base
register. This example uses the global pointer as the base register. Figure 2.13
shows that $gp is initialized to 1000 8000hex. To get the address 1000 0000hex (the address of word X), we place 8000hex in the address field of lw at address 40 0000hex. Similarly, we place 8020hex in the address field of sw at address 40 0100hex to get the address 1000 0020hex (the address of word Y).
Page 128
根据指令lw
和sw
的MIPS-32指令集,立即数偏移操作数被添加到寄存器操作数。
但是
1000 8000十六进制 + 8000十六进制 = 1001 0000十六进制 != 1000 0000十六进制
1000 8000十六进制 + 8020十六进制 = 1001 0020十六进制 != 1000 0020十六进制
所以也许我误解了什么,偏移量被减去了?即使是这样:
1000 8000十六进制 - 8000十六进制 = 1000 0000十六进制 == 1000 0000十六进制
1000 8000十六进制 - 8020十六进制 = FFFF FE0十六进制 != 1000 0020十六进制
这里发生了什么?
图2.13:
指令字中的 16 位偏移量在添加到基地址之前符号扩展到 32 位。
因此,如果在指令字中找到的偏移量为 0x8000,则得到 0x10008000 + 0xFFFF8000 == 0x10000000(当结果被截断为 32 位时)。第二个例子也类似。
我正在阅读 Computer Organization and Design 的第 2.12 章,试图理解 MIPS-32 链接器的逻辑。我了解链接两个目标文件和绝对引用链接的概念。我不明白的是下面引用的段落解释了计算绝对地址的逻辑。
The load and store addresses are harder because they are relative to a base register. This example uses the global pointer as the base register. Figure 2.13 shows that $gp is initialized to 1000 8000hex. To get the address 1000 0000hex (the address of word X), we place 8000hex in the address field of lw at address 40 0000hex. Similarly, we place 8020hex in the address field of sw at address 40 0100hex to get the address 1000 0020hex (the address of word Y).
Page 128
根据指令lw
和sw
的MIPS-32指令集,立即数偏移操作数被添加到寄存器操作数。
但是
1000 8000十六进制 + 8000十六进制 = 1001 0000十六进制 != 1000 0000十六进制
1000 8000十六进制 + 8020十六进制 = 1001 0020十六进制 != 1000 0020十六进制
所以也许我误解了什么,偏移量被减去了?即使是这样:
1000 8000十六进制 - 8000十六进制 = 1000 0000十六进制 == 1000 0000十六进制
1000 8000十六进制 - 8020十六进制 = FFFF FE0十六进制 != 1000 0020十六进制
这里发生了什么?
图2.13:
指令字中的 16 位偏移量在添加到基地址之前符号扩展到 32 位。
因此,如果在指令字中找到的偏移量为 0x8000,则得到 0x10008000 + 0xFFFF8000 == 0x10000000(当结果被截断为 32 位时)。第二个例子也类似。