我正在尝试解决/理解我的 MIPS 汇编编程任务中可能出现的问题。这是相当基本的,我们必须实现一个递归调用,更新“计数器”并在计数器达到 0 时退出循环。根据 PCSpim,我的错误在我运行程序时显示计数器值为 NULL。
.data
string: .asciiz "Recursive call counter "
.text
.globl main
main:
subu $sp, $sp, 32 # create stack frame
sw $ra, 28($sp) # save ($fp, $ra) registers
sw $fp, 24($sp)
addu $fp, $sp, 28 # set up the new frame pointer
sw $s0, 20($sp) # save other GPR’s
li $s1, 10 # load counter to $s1
li $v0, 4 # print counter message and counter
la $a0, string
syscall
li $v0, 4
la $a0, ($s1)
syscall
jal recursive_call # jump to recursive call
lw $s0, 20($sp) # restore registers
lw $fp, 24($sp) # restore SP, FP, $ra for the caller
lw $ra, 28($sp)
addu $sp, $sp, 32 # restore the caller's stack pointer
jr $31 #end program
recursive_call:
subu $sp, $sp, 32 # create stack frame
sw $ra, 28($sp) # save ($fp, $ra) registers
sw $fp, 24($sp)
addu $fp, $sp, 28 # set up the new frame pointer
sw $s0, 20($sp) # save other GPR’s
sub $s1, $s1, 1 # subtract one from counter
li $v0, 4 #print counter number
la $a0, ($s1)
syscall
beq $s0, $zero, SKIP # if counter = 0, go to skip
jal recursive_call # jump to recursive call
SKIP:
lw $s0, 20($sp) # restore registers
lw $fp, 24($sp) # restore SP, FP, $ra for the caller
lw $ra, 28($sp)
addu $sp, $sp, 32 # restore the caller's stack pointer
jr $ra
任何帮助将不胜感激。我将继续进行故障排除,看看我是否想出了任何问题。