关于MIPS中%hi()与%lo()的一点疑问
在看《See MIPS Run(2nd Edition)》的Chapter 9 Reading MIPS Assembly Language中的9.4 Addressing Modes中,碰见这样一段话:
The constructs %hi() and %lo() represent the high and low 16 bits of the address. This is not quite the straightforward division into low and high halfwords that it looks, because the 16-bit offset field of an lw is interpreted as signed. So if the addr value is such that bit 15 is a 1, then the %lo(addr) value will act as negative, and we need to increment %hi(addr) to compensate:
图片版的原文在此:
文中说:
because the 16-bit offset field of an lw is interpreted as signed. So if the addr value is such that bit 15 is a 1, then the %lo(addr) valuwill act as negative, and we need to increment %hi(addr) to compensate:
不是很懂为什么“need to increment %hi(addr) to compensate”。。。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为
%lo(addr)
是一个有符号16位整数,也就是说bit#15是符号位,因此0x8000
是一个负数。在做相加计算时,其符号位扩展到高16bit,也就变成
0xFFFF8000
, 要想得到原来的地址0x10008000
,%hi(addr)
必须加1,0x1001.0000 + 0xFFFF.8000 = 0x1000.8000
.把
lw
、sw
指令的offset
字段设为有符号整数的好处是可以寻址寄存器前后两个方向的地址,如果设计成无符号整数就只能寻址大于等于寄存器值的地址范围了。