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
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:
This will load and run the
exitsystem call (which has a code of 10.)