MIPS函数系统调用打印随机数/内存地址而不是参数
我是MIPS的新手,我正在尝试编写一个非常基本的功能,该功能需要4个数字(因此4个参数)并将它们添加在一起。我正在这样做,所以其中3个数字在内存中硬编码,用户输入收到了第四个数字(x)。
现在,一旦我进入该功能,我只是想打印所有4个数字(只是为了验证它们都正确地通过了),但是它是在打印一个随机的长数(地址?),而我无法打印告诉发生了什么。
.data
# initialize variables
num1:
.word 10
num2:
.word 15
num3:
.word -7
x:
.word 0
input_msg:
.asciiz "Enter a number for x :"
.text
.globl main
main:
addiu $sp, $sp, -4
#get value of x from user input
la $a0, input_msg
jal getInteger
move $s0, $v0 #returned value goes into $s0 (this all works correctly)
#parameters for function call
move $a0, $s0
la $a1, num1
la $a2, num2
la $a3, num3
jal add_nums
addiu $sp, $sp, 4
# end of program
li $v0, 10
syscall
add_nums:
#allocate stack space
addiu $sp, $sp, -16
li $v0, 1
syscall
li $v0, 1
syscall
li $v0, 1
syscall
li $v0, 1
syscall
它打印了我认为是任意的“ 111111268500992”,但是这里发生了什么?我以为我理解了功能电话,但这让我感到困惑。
I'm new to MIPS and I'm trying to write a very basic function that takes 4 numbers (so 4 parameters) and adds them together. I'm doing it so 3 of the numbers are hard-coded in memory and the 4th number (x) is received by user input.
Right now I'm just trying to print all 4 numbers once I'm inside the function (just to verify that they were all passed in correctly), but instead it's printing a random long number (the address?) and I can't tell what's going on.
.data
# initialize variables
num1:
.word 10
num2:
.word 15
num3:
.word -7
x:
.word 0
input_msg:
.asciiz "Enter a number for x :"
.text
.globl main
main:
addiu $sp, $sp, -4
#get value of x from user input
la $a0, input_msg
jal getInteger
move $s0, $v0 #returned value goes into $s0 (this all works correctly)
#parameters for function call
move $a0, $s0
la $a1, num1
la $a2, num2
la $a3, num3
jal add_nums
addiu $sp, $sp, 4
# end of program
li $v0, 10
syscall
add_nums:
#allocate stack space
addiu $sp, $sp, -16
li $v0, 1
syscall
li $v0, 1
syscall
li $v0, 1
syscall
li $v0, 1
syscall
It prints "111111268500992" which I assume is arbitrary, but what's really going on here? I thought I understood function calls but this has me perplexed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论