【发布时间】:2016-09-25 15:40:10
【问题描述】:
我有两个问题:
1)> 第2行发生了什么。'la'伪指令指的是加载地址,而不是文字'3444'应该有一个标签。它如何加载文字的地址
2)> 如果将第 3 行替换为“li $a0 3444”,它将 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(load address) 和 li(load immediate) 都转换为相同的指令,即将文字加载到 #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!"
【问题讨论】:
-
无论如何,您都不应该尝试在 cmets 中发布代码。将说明编辑到您的答案中是正确的做法。
-
标签是地址。它们本身并没有“存储”在任何地方,它们只是用符号而不是数字地址写入地址的有用方法。
标签: assembly printing int load mips