MIPS寻址模式下寄存器间接寻址和基址加偏移量的区别?
寄存器间接和基址加偏移之间有什么区别?它如何影响您在 MIPS 架构上编写汇编的方式?我认为这意味着您只能在指令中引用寄存器,并且该寄存器必须指向更多指令?
What is the difference between register indirect and base plus offset, and how does it affect how you write assembly on the MIPS architecture? I think it means that you can only reference the register in an instruction, and that register has to point to more instructions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“寄存器间接”寻址意味着将由寄存器使用的地址
指令(称为“有效地址”)取自a的内容
寄存器,而不是直接在指令本身中编码
(这是“绝对”寻址)。 MIPS 有针对这两种情况的跳转指令
寻址模式:
表示“跳转到地址
0x1234
”(绝对寻址),而表示“跳转到
$ra
寄存器中包含的地址”(寄存器间接寻址)寻址)。
“基址加偏移量”寻址意味着基地址取自
寄存器的内容,然后是偏移量(在指令中编码
本身)被添加。 MIPS 使用这种寻址模式进行加载和存储。为了
示例:
...如果
$a0
包含0x1234
,则$t0
将加载单词 at地址
0x1234
(有效地址是寄存器的内容,加上偏移量为 0),
$t1
将加载地址0x1238
处的字(有效地址是寄存器的内容加上偏移量4)。
可以看到,当偏移量为0时,相当于寄存器间接
寻址。
"Register indirect" addressing means that the address which will be used by the
instruction (known as the "effective address") is taken from the contents of a
register, rather than being encoded directly within the instruction itself
(which is "absolute" addressing). MIPS has jump instructions for both of these
addressing modes:
means "jump to address
0x1234
" (absolute addressing), whereasmeans "jump to the address contained in the
$ra
register" (register indirectaddressing).
"Base plus offset" addressing means that a base address is taken from the
contents of a register, and then an offset (which is encoded in the instruction
itself) is added. MIPS uses this addressing mode for loads and stores. For
example:
...if
$a0
contains0x1234
, then$t0
will be loaded with the word ataddress
0x1234
(the effective address is the contents of the register, plusan offset of 0), and
$t1
will be loaded with the word at address0x1238
(the effective address is the contents of the register, plus an offset of 4).
As you can see, when the offset is 0, this is equivalent to register indirect
addressing.
寄存器间接寻址模式只是偏移量为零时基址加偏移量寻址模式的一种特例。
当您的结构具有多个数据项并且想要引用这些项时,可以使用基址加偏移量寻址模式。基址寄存器指向结构的开头,偏移量用于提取特定项。示例是加载虚拟方法的地址,其中基址寄存器指向虚拟方法表的基址,偏移量指示感兴趣的方法。另一个例子是引用堆栈上函数的局部变量,其中基址寄存器指向函数的堆栈帧,偏移量指示感兴趣的特定变量。
Register indirect addressing mode is just a special case of base plus offset addressing mode when offset is zero.
The base plus offset addressing mode is used when you have a structure with multiple data items and want to refer to the items. The base register points to the beginning of the structure and offset is used to extract a particular item. Example is loading an address of a virtual method where base register points to the base of the virtual method table and an offset indicates the method of interest. Another example is referring to function's local variables on the stack where base register points to the stack frame of the function and offset indicates the particular variable of interest.