简体   繁体   English

在MIPS / SPIM中,li和lw之间有什么区别?

[英]In MIPS/SPIM, whats the difference between li and lw?

After realizing how lost I am with assembly language and using MIPS, I decided to start from the basics and actually understand it. 在意识到我使用汇编语言并使用MIPS失去了多少之后,我决定从基础开始并实际理解它。

Obviously MIPS code has specific purposes, but a lot of the stuff seems to do similar things and I'm having a hard time understanding some of the differences. 显然MIPS代码有特定的用途,但很多东西似乎做了类似的事情,我很难理解一些差异。

What is the difference between loading immediate.. (li) and loading a word.. (lw)? 加载立即..(li)和加载单词有什么区别..(lw)? I'm not even sure what a "word" is. 我甚至不确定“单词”是什么。 Or what the following does: 或者以下内容:

li $t0,y
lw $t0,0($t0)

Is it loading y into the register $t0 in the first line? 是否在第一行中加载y到寄存器$ t0? And then loading 0($t0) as y? 然后加载0($ t0)作为y?

Sorry, this is probably a really dumb question. 对不起,这可能是一个非常愚蠢的问题。 If anyone could just explain what those two lines are doing and the difference between li/lw, i'd greatly appreciate it. 如果有人能够解释这两条线正在做什么以及li / lw之间的区别,我会非常感激。 Thanks! 谢谢!

A word is a fixed-length sequence of bits. 一个word是固定长度的比特序列。
On MIPS32, a word is 32 bits wide. 在MIPS32上,一个word是32位宽。
The instruction lw $regA, offset($regB) loads a word from the memory location specified by offset($regB) into register regA . 指令lw $regA, offset($regB)将一个字从offset($regB)指定的存储单元加载到寄存器regA

By contrast, li reg, immediate is not a true instruction . 相比之下, li reg, immediate 不是真正的指示 No MIPS cpu can execute li . 没有MIPS cpu可以执行li It's a pseudo-instruction that is turned into a sequence of two instructions by the assembler: 它是一个伪指令,由汇编程序转换为两个指令的序列:

lui $reg, [most significant 16 bits of immediate]
ori $regA, $regA, [least significant 16 bits of immediate]

lui loads the upper 16 bits of a 32-bit register with an immediate constant from the instruction, setting the lower 16 bits to zero. lui从指令加载一个32位寄存器的高16位,并使用一个立即数,将低16位设置为零。
ori takes the content of $regA , does a bitwise logical OR with the 16 bit immediate from the instruction, and stores the result back into $regA . ori获取$regA的内容,与指令中的16位立即执行按位逻辑OR,并将结果存储回$regA

So, to sum up: li $reg, immediate will always put the same immediate into a register, while lw $regA, offset($regB) will load the current value from the memory location offset($regB) . 因此,总结一下: li $reg, immediate总是相同的立即数放入寄存器,而lw $regA, offset($regB)将从内存位置offset($regB)加载当前值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM