MIPS" la"伪指令加载文字的地址

时间:2016-09-25 15:40:10

标签: assembly printing int load mips

我在这里有两个问题:

1)>第2行发生了什么。' la'伪指令是指加载地址,而不是文字“3444”。应该有一个标签。如何加载文字的地址

2)>如果你用" li $ a0 3444"替换第3行它将3444加载到寄存器#a0而不是地址。输出仍然是相同的。我想问的是,系统调用怎么知道#a0是变量的地址或变量本身。怎么可能打印整数的子程序是否正确工作#a0中存储的参数是地址还是整数值本身。

.text

      li $v0 1 
 >>2  la $a0 3444   # When i replace 3444 literal with the label  'anint' it makes sense and the output of course is the same
      syscall


.data

 anint: .word 3444

输出:

3444

更新#2:我无法在评论中发布代码,所以......

IF la(加载地址)和li(加载立即数)都转换为相同的指令i-e将文字加载到#a0然后从下面的代码段解释第3行。

      .text


      li #v0 4
>>3   la #a0 msg  #This loads the address of the label 'msg in #a0' not the label itself    
      syscall





      .data

       msg: .asciiz "This is a long string that can't be saved in the register!"

1 个答案:

答案 0 :(得分:2)

  

系统调用怎么知道#a0是变量的地址还是变量本身

它没有。 SPIM / MARS中的系统调用1始终在$a0中打印

li $a0,3444la $a0,3444被翻译成相同的内容(某些指令会将值3334加载到注册表$a0中,例如ori $a0, $0, 3334)。< / p>

相关问题