【发布时间】:2022-01-23 06:12:33
【问题描述】:
作为我的 uni 报告的一部分,它希望我编辑一些 MIPS 代码并将重复代码放入子例程中,但是,每当我调用我的子例程时,它就会陷入重复整个子例程的无限循环中。该程序假设从用户那里获取 4 个输入并将它们加在一起并显示在没有子例程的情况下工作的总数,我不确定我的代码是否遗漏了某些内容,或者我只是写错了?谢谢你的帮助! :]
.data
enterMsg1: .asciiz "Please enter the last four digits of your student id \n"
enterMsg2: .asciiz "Press enter between each digit \n"
enterMsg3: .asciiz "Enter next digit \n"
totalMsg1: .asciiz "The total of the digits is: "
.text
# output the initial instruction text to the console
addi $v0, $zero, 4
la $a0, enterMsg1
syscall
# output the second instruction text to the console
addi $v0, $zero, 4
la $a0, enterMsg2
syscall
# read an integer from keyboard input and store the input in $s0 for the total
addi $v0, $zero, 5
syscall
add $s0, $zero, $v0
jal NextDigit
jal NextDigit
jal NextDigit
# output the text asking for the next digit to the console
# then receive the input, add to total ($s0)
NextDigit:
addi $v0, $zero, 4
la $a0, enterMsg3
syscall
addi $v0, $zero, 5
syscall
add $s0, $s0, $v0
jr $ra
# output the total instruction text to the console
addi $v0, $zero, 4
la $a0, totalMsg1
syscall
add $a0, $s0, $zero
addi $v0, $zero, 1
syscall
addi $v0, $zero, 10
syscall ```
【问题讨论】:
标签: assembly mips mars-simulator