Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly MIPS:在基偏移量寻址中使用标签_Assembly_Mips - Fatal编程技术网

Assembly MIPS:在基偏移量寻址中使用标签

Assembly MIPS:在基偏移量寻址中使用标签,assembly,mips,Assembly,Mips,我试图在基偏移量寻址模式中使用标签作为偏移量, 用于在类似外壳代码的环境中访问全局变量。代码和数据的基址存储在$s7中,我正在尝试这样做: # global variable @ offset 20 in code, foobar: .word <non-constant value> # ... lw $s0, foobar($s7) 是否有任何方法可以让它将foobar解释为立即值,就像执行addiu$t0,$t1,foobar时一样,按预期转换为addiu$t0,$t1

我试图在基偏移量寻址模式中使用标签作为偏移量, 用于在类似外壳代码的环境中访问全局变量。代码和数据的基址存储在
$s7
中,我正在尝试这样做:

# global variable @ offset 20 in code, 
foobar: .word <non-constant value>

# ...

lw $s0, foobar($s7)
是否有任何方法可以让它将
foobar
解释为立即值,就像执行
addiu$t0,$t1,foobar
时一样,按预期转换为
addiu$t0,$t1,20

到目前为止,翻阅这些文件还没有产生任何有用的结果


提前谢谢

我找到了解决办法。现在我将使用
lw$s0,%lo(foobar)($s7)
,只要标签是
就行,为什么要通过运行时值(寄存器)来寻址编译时/链接时常量?这毫无意义。这个值实际上不是常数,我只是用它作为例子!将其视为一个全局变量-我更新了问题以澄清这一点@EOF:这是位置无关的代码,但MIPS没有PC相对寻址模式。(只有reg+disp16,我认为这是一个有符号的置换,因此OP的答案实际上适用于labels@PeterCordes现代MIPS发行版中的PIC有
[d]addiupc
)。
lui     $s0, 0x0
addu    $s0, $s0, $s7
lw      $s0, 20($s0)