Reading and printing an integer in mips

前端 未结 2 1628
梦毁少年i
梦毁少年i 2020-12-30 15:48

My program is suppose to read an integer and print it back to the user but every time it just prints 268501230 no matter what is entered. Any help would be appreciated.

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 16:32

    #reads one integer from user and saves in t0
    li $v0, 5
    la $t0, buffer
    syscall
    

    That's not how syscall 5 works. The integer is returned in $v0, so the code ought to be something like:

    li $v0,5
    syscall
    move $t0,$v0
    

    li $v0, 1       
    li $t0, 5       # $integer to print
    syscall 
    

    You're using the wrong register here as well. The integer to print should go into $a0, not $t0.

    Here's a list of syscalls and the registers they use.

提交回复
热议问题