简单mips中的无限循环 [英] infinite loop in simple mips
问题描述
我正在尝试了解$ ra,所以我想要的输出是"mainfunction1main",通过主调用function1,function1返回main,并且main完成.但是由于某种原因,我遇到了一个无限循环,该循环显示"mainfunction1mainfunction1 ......".我在做什么错了?
I'm trying to learn about $ra, so the output I want is "mainfunction1main" , by main calling function1, function1 returning to main, and main finishing. but for some reason I'm getting an infinite loop which prints "mainfunction1mainfunction1......" what am I doing wrong?
.data
mainstring: .asciiz "main"
string1: .asciiz "function1"
string2: .asciiz "function2"
string3: .asciiz "function3"
.text
main: la $a0,mainstring
li $v0, 4
syscall
jal function1
la $a0, mainstring
syscall
function1: la $a0, string1
syscall
jr $ra
推荐答案
就像JasonD所说的那样,您需要在main末尾退出程序.您需要做的就是在main的末尾添加两行,就像这样:
Like JasonD said, you need to exit your program at the end of main. All you need to do is append two lines at the end of main, like so:
main:
# ... previous stuff
li $v0, 10
syscall
这将加载并运行exit
系统调用(代码为10)
This will load and run the exit
system call (which has a code of 10.)
这篇关于简单mips中的无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!