我正在研究MIPS中的字符串逆转程序,对于MIPS / Assembly的内部工作方式我基本上一无所知。我在第36行遇到运行时错误,循环中有“sb $ t6,stringreverse($ t3)”行。有人能解释一下吗?
.data
nl: .asciiz "\n"
inputPrompt: .asciiz "Please enter an integer:\n"
theString: .space 32
theInteger: .word 1
.text
main:
la $a0, inputPrompt #load address a0 with prompt
li $v0, 4 #load system call, print string into v0
syscall
li $v0, 5 #load system call, read int into v0
syscall
sw $v0, theInteger #store saved int into $t0
li $v0, 8 #load system call, read string with mem address
la $a0, theString #load address of reserved string space
lw $a1, theInteger #load address of saved int length for string
syscall
lw $t0, theInteger
add $a1,$zero,$t0 #pass lenght of string
jal stringreverse #reverse the string
stringreverse:
add $t0,$a0,$zero #starting address
add $t1,$zero,$zero
add $t3,$zero,$zero #i = 0
addi $t2,$a1,-2 #j = length-1
loop:
add $t5,$t0,$t2
lb $t6,0($t5) #the lb string[j]
sb $t6,stringreverse($t3)
addi $t2,$t2,-1 #j--
addi $t3,$t3,+1 #i++
slt $t7,$t2,$t1
beqz $t7,loop
exit:
li $v1, 4 #system call to print reversed string
la $a2, 0($a1)
syscall
li $v0, 10
syscall # Exit program