关于加载字(lw)与加载地址(la)以及mips汇编中的偏移量的混淆? [英] Confusion about load word (lw) vs load address(la) and offsets in mips assembly?

查看:1247
本文介绍了关于加载字(lw)与加载地址(la)以及mips汇编中的偏移量的混淆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我刚接触汇编,所以有很多问题.例如,如果我在数据段中输入

So I'm pretty new to assembly and I got so many questions. For example, if in the data segment I type this

.data

n:.word 4

在文本段中

.text
lw $t0, n

$ t0现在是否存储值4或n的地址? 因为我知道如果n是一个数组,并且我键入lw $ t0 4(n)$ t0存储n(内容)的第一个值.如果我键入lw $ t0 n,那么$ t0将存储地址.

Does $t0 now store the value 4 or the address of n? Because I know that if n were an array and if I type lw $t0 4(n) $t0 stores the first VALUE of n(the content). And if I type lw $t0 n then $t0 stores the address.

我还想知道是否将偏移量设置为4来注册$ 0,如下所示:

Also I am wondering if I were to set an offset of 4 to register $0 like this:

lw $t0 4($0)

$ t0会保持0吗?

would $t0 just hold 0?

推荐答案

lw从内存中加载单词.
lw $t0, n从符号n的地址中读取.
lw $t0, 4($t1)从生成为$t1 + 4的地址中读取.
lw $t0, 0x10000从地址0x10000读取.

lw load a word from memory.
lw $t0, n reads from the address of the symbol n.
lw $t0, 4($t1) reads from the address generated as $t1 + 4.
lw $t0, 0x10000 reads from the address 0x10000.

除了第二个,都是伪指令.

Apart from the second, all are pseudo-instructions.

la加载地址.
la $t0, n将符号n的地址放在$t0中.
la $t0, 4($t1)将生成为$t1 + 4的地址放在$0中.

la load an address.
la $t0, n puts the address of the symbol n in $t0.
la $t0, 4($t1) put the address generated as $t1 + 4 in $0.

这些都是伪指令.

li立即加载.
li $t0, 10000将立即数10000放入$t0.

li load an immediate.
li $t0, 10000 puts the immediate 10000 in $t0.

这是一条伪指令.

中心点是MIPS具有用于I型指令的16位立即数(常量),因此lw不允许移动大于0x10000的值或不允许访问和大于0x10000的地址.
汇编器通过生成两个或更多指令来解决它.
理论上不需要la,可以使用li加载符号的地址,因为该地址在此上下文中是立即数,但引入了特定的助记符.

The central point is that MIPS has 16-bit immediates (constants) for I-type instructions, so the real form of li and lw don't permit to move a value greater than 0x10000 or access and address above 0x10000.
The assembler gets around it by generating two or more instructions.
la isn't needed in theory, li could be used to load the address of a symbol since the said address is an immediate in this context but a specific mnemonic was introduced instead.

这篇关于关于加载字(lw)与加载地址(la)以及mips汇编中的偏移量的混淆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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