我遇到了一些错误,第一个错误位于lw $t3, 4($t7)
,我不确定是否正确访问了数组,或者是否将数组索引分配给错误的值或什么值,但是它不起作用并且我收到此错误:Error in D:\bubble.asm line 77: Runtime exception at 0x00400074: address out of range 0x10400000
。我正在尝试进行冒泡排序,而我只是手动输入要排序的值。如果有更好的方法,请告诉我。为什么这不起作用?整个过程看起来像这样:
.data
arr: .space 32
.text
addi $s0, $zero, 4
addi $s1, $zero, 6
addi $s2, $zero, 1
addi $s3, $zero, 8
addi $s4, $zero, 3
addi $s5, $zero, 2
addi $s6, $zero, 7
addi $s7, $zero, 5
la $t7, arr
sw $s0, 0($t7)
addi $t7, $t7, 4
sw $s1, 0($t7)
addi $t7, $t7, 4
sw $s2, 0($t7)
addi $t7, $t7, 4
sw $s3, 0($t7)
addi $t7, $t7, 4
sw $s4, 0($t7)
addi $t7, $t7, 4
sw $s5, 0($t7)
addi $t7, $t7, 4
sw $s6, 0($t7)
addi $t7, $t7, 4
sw $s7, 0($t7)
addi $t7, $t7, 4
addi $t6, $zero, 0
LOOPi:
li $t6, 0 # resets hasSwapped back to 0 (false)
LOOPii:
lw $t2, 0($t7) # get first int
lw $t3, 4($t7) # get second int
slt $t5,$t2,$t3 # if n[0] < n[+1] set t5 = 1
addi $t7, $t7, 4 #increment
bne $t5,$zero, LOOPii # if $t5 == 0 restart loop (dont swap)
#else
li $t6, 1 # hasSwapped = true
move $t5,$t2 # move $t2 into $t5
move $t2,$t3 # move $t3 into $t2
move $t3,$t5 # move $t5 into $t3
addi $t7, $t7, -4
sw $t2, 0($t7) # put values back
sw $t3, 4($t7)
addi $t7, $t7, 4
bne $t6, $zero, LOOPi