MIPS(汇编)打印功能未按预期工作
我正在学习 MIPS 并试图理解函数调用之类的东西。我编写了这个基本的“printValue”函数来打印全局内存中定义的变量的值,但它打印的是 0 (它应该打印“2”,因为 a2 已初始化),我不明白为什么。这是我的代码:
.data
# Allocate variables in global memory
a2:
.word 2
a1:
.word 3
a0:
.word 5
x:
.word 0
result:
.word 0
output_msg:
.asciiz "The result is "
newl:
.asciiz "\n"
.align 2
.text
.globl main
main:
#prologue (push stack space)
addiu $sp, $sp, -4
la $a0, a2
jal printValue
#epilogue
addiu $sp, $sp, 4
# Signal end of program
li $v0, 10
syscall
printValue:
addiu $sp, $sp, -4 # Allocate space on the stack
# Print value
li $v0, 1
move $a0, $s0
syscall
jr $ra
哪里出了问题?感谢您的帮助,我真的很感激!
I'm learning MIPS and trying to understand function calls and stuff. I wrote this basic 'printValue' function to print the value of a variable defined in Global memory, but it's printing 0 instead (it should print '2', as a2 is initialized) and I can't understand why. Here's my code:
.data
# Allocate variables in global memory
a2:
.word 2
a1:
.word 3
a0:
.word 5
x:
.word 0
result:
.word 0
output_msg:
.asciiz "The result is "
newl:
.asciiz "\n"
.align 2
.text
.globl main
main:
#prologue (push stack space)
addiu $sp, $sp, -4
la $a0, a2
jal printValue
#epilogue
addiu $sp, $sp, 4
# Signal end of program
li $v0, 10
syscall
printValue:
addiu $sp, $sp, -4 # Allocate space on the stack
# Print value
li $v0, 1
move $a0, $s0
syscall
jr $ra
Where is it going wrong? Thank you for any help, I really appreciate it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论