我的代码遇到问题。我目前在第28行遇到运行时错误:0x00400044处的运行时异常:地址超出范围0x00000001。
程序应该接受输入并按降序返回。
main:
move $s0,$gp #get the intial point to save array
addi $t0,$0,1 # $t0 = 1
add $t1,$zero,$zero #
add $t2,$zero,$zero #
add $t3,$zero,$zero #
add $t6,$zero,$zero
add $t4,$zero,$zero
sub $t7,$zero,1 # terminate
li $v0,4 # system call to put the string
la $a0,msg1 #
syscall #
add $s1,$s0,$zero # copy the pointer to array in $s1
entervalues:
li $v0,5 # get the value in v0
syscall #
beq $v0,$t7,bubblesort # end of string run to bubblesort
lb $v0,0($s1) # **HERE IS THE ERROR**
addi $s1,$0,1 # move the $s1 pointer by one
add $t5,$s1,$zero # $t5 stores the end value
j entervalues
bubblesort:
add $t4,$s0,$zero
addi $t6,$0,1 #s1-1 -> s0
sub $s1,$s1,$t0
beq $s1,$s0,ending
add $s2,$s0,$zero
loopinterno:
lb $t1,0($s2) # first element
lb $t2,1($s2) # second element
slt $t3,$t2,$t1 #
beq $t3,$zero,proximo #
sb $t2,0($s2) #
sb $t1,1($s2) #
proximo:
addi $s2,$0,1 #
bne $s2,$s1,loopinterno #
li $v0,4 # system call to put the string
la $a0,msg5 #
syscall #
li $v0,4 # system call to put the string
la $a0,msg4 #
syscall #
li $v0,4 # system call to put the string
la $a0,msg5 #
syscall #
imprime:
li $v0,1
lb $a0,0($t4)
syscall
li $v0,4
la $a0,msg2
syscall
addi $t4,$0,1
bne $t4,$t5,imprime
jal bubblesort
ending:
li $v0,4 # system call to put the string
la $a0,msg6 #
syscall #
li $v0,5
非常感谢任何帮助!
答案 0 :(得分:1)
您的问题似乎出现在说明中:
addi $s1,$0,1 # move the $s1 pointer by one
这不是你的评论所说的。它只是立即置于$s1
中。 addi
添加第二个和第三个参数,并将加法放在第一个参数中。
您应该已经发出:
addi $s1,$s1,1 # move the $s1 pointer by one
你在代码中做同样的事情。例如,当您发出
时 addi $t6,$0,1 #s1-1 -> s0
你可能意味着
addi $t6,$t6,1 #s1-1 -> s0