MIPS-32链接器如何转换LW和SW地址? [英] How does a MIPS-32 linker convert lw and sw addresses?

查看:81
本文介绍了MIPS-32链接器如何转换LW和SW地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读

解决方案

在指令字中找到的16位偏移在被添加到基址之前,先符号扩展到32位./p>

因此,如果在指令字中找到的偏移量为0x8000,则将得到0x10008000 + 0xFFFF8000 == 0x10000000(当结果被截断为32位时).同样,对于第二个示例.

I am reading Chapter 2.12 of Computer Organization and Design, trying to understand the logic of a MIPS-32 linker. I understand the concept of linking two object files and absolute reference linking. What I don't understand is the quoted paragraph below explaining the logic for calculating absolute addresses.

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

According to the MIPS-32 instruction set for instructions lw and sw, the immediate offset operand is added to the register operand.

But
1000 8000hex + 8000hex = 1001 0000hex != 1000 0000hex
1000 8000hex + 8020hex = 1001 0020hex != 1000 0020hex

So maybe I am misunderstanding something and the offsets are being subtracted? Even if that was the case:

1000 8000hex - 8000hex = 1000 0000hex == 1000 0000hex
1000 8000hex - 8020hex = FFFF FE0hex != 1000 0020hex

What is happening here?

Figure 2.13:

解决方案

The 16-bit offsets found in the instruction words are sign-extended to 32 bits before being added to the base address.

So if the offset found in the instruction word is 0x8000, you get 0x10008000 + 0xFFFF8000 == 0x10000000 (when the result is truncated to 32 bits). And similarly for the second example.

这篇关于MIPS-32链接器如何转换LW和SW地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆