MIPS:LW(加载字)指令 [英] MIPS: lw (load word) instruction

查看:3320
本文介绍了MIPS:LW(加载字)指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

lw $s0,8($0)lw $s0,0($v0)相同吗?

我看不出有什么区别.我认为8代表偏移量,这意味着我们需要$ 0的地址并在地址中加上2(8/4).

I do not see the difference. I think the 8 represents the offset, which means we need the addres of $0 and add 2 (8/4) to the address.

我的问题是关于lw指令和MIPS寄存器集.我很难理解偏移量是如何工作的...

My question is about the lw instruction and the MIPS register set. Its pretty difficult for me to understand how the offset exactly works...

推荐答案

虽然在某些情况下它们的行为相似,但它们并不相同. lw指令的格式如下:

They are not the same, although in some circumstances they will behave alike. The format of the lw instruction is as follows:

lw RegDest, Offset(RegSource)

其中RegDest和RegSource是MIPS寄存器,而Offset是立即数.

where RegDest and RegSource are MIPS registers, and Offset is an immediate.

这意味着,将寄存器RegSource的内容与指定的偏移量相加后,将地址中包含的字加载到寄存器RegDest中.源地址必须是字对齐的(即4的倍数)

It means, load into register RegDest the word contained in the address resulting from adding the contents of register RegSource and the Offset specified. The resulting source address must be word-aligned (i.e. multiple of 4)

因此, lw $s0,8($0)表示将位于$0加8的地址中的字的内容加载到$s0中.由于$0是寄存器$zero,其始终包含常数零,因此将加载位于$s0中的字.绝对地址8放入$s0.

Therefore, lw $s0,8($0) means to load in $s0 the contents of the word located at address specified by $0 plus 8. As $0 is register $zero which will always contain the constant zero, it will load the word located in absolute address 8 into $s0.

lw $s0,0($v0)意味着将$v0指定的地址中的单词内容加载到$s0中.如果$v0包含值8,则这两个指令具有相同的效果.如果$v0不是4的倍数,则指令将生成一个寻址陷阱.

lw $s0,0($v0) means to load in $s0 the contents of the word located at the address specified by $v0. If $v0 contains the value 8 then both instructions have the same effect. If $v0 is not a multiple of 4, the instruction will generate an addressing trap.

通常,lw是伪指令,从某种意义上说,汇编程序可以发出一个以上的指令来完成该指令.偏移量(位移)必须为16位有符号值. 如果您的指令具有更多位的立即数,则汇编程序通常将使用临时寄存器($at)来保存立即数的内容,然后发出等效指令以执行预期的行为.您可能会使用反汇编程序或MIPS监视器(也正在使用MARS模拟器检查代码)看到此操作.

Usually lw is a pseudoinstruction in the sense that the assembler may emmit more than one instruction to accomplish the instruction. The offset (displacement) has to be a 16-bit signed value. If your instruction has an immediate with more bits, the assembler will usually use a temporary register ($at) to hold the contents of the immediate and then emmit equivalent instructions to perform the intended behavior. You may see this in action using a dissassembler or a MIPS monitor (also inspecting the code with MARS simulator).

这篇关于MIPS:LW(加载字)指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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