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
どんな助けでも大歓迎です。引き続きトラブルシューティングを行い、何か思いついたかどうかを確認します。