1

I am having a few errors, the first one at lw $t3, 4($t7) I'm not sure if I'm accessing the array correctly or if I assign the array indexes to values wrong or what, but its not working and I get this error: Error in D:\bubble.asm line 77: Runtime exception at 0x00400074: address out of range 0x10400000. I'm trying to do a bubble sort and I'm simply manually entering the values to be sorted. If there is a better way to do this let me know. Why isn't this working? The whole thing looks like this:

.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
Isaak Johnson
  • 129
  • 3
  • 8

0 Answers0