我有一个程序将使用选择排序算法方法对字符串进行排序。该程序将接收用户输入的字符串并使用选择排序算法对其进行排序。我的问题是,当我运行它时,我收到一条错误消息,提示“获取地址未在字边界上对齐”。我应该怎么做才能解决这个问题?我对 mips 编程比较陌生。
.data
prompt: .asciiz "\n\nEnter an string of characters: "
result: .asciiz "\n\nHere is the string you entered: "
buffer: .space 80
length: .word 80
before: .asciiz "Before sort:\n"
space: .asciiz " "
after: .asciiz "\n\nAfter Sort\n"
newLine: .asciiz "\n"
.text
.globl main
main:
#Prints the prompt string
li $v0, 4
la $a0, prompt
syscall
#reads string from user and saves in $a0
li $v0, 8
la $a0, buffer
li $a1, 80
syscall
#Prints the result string
li $v0, 4
la $a0, result
syscall
#Prints the string entered by the user
la $a0, buffer
li $v0, 4
syscall
li $t5, 0 # t5 is k = 0
la $t7, length
lw $t7, 0($t7) # t7 = length
addi $t8, $t7, -1 # t8 = length - 1
la $t6, 0($a0) # t6 = address of the array
outerLoop: slt $t0, $t5, $t8 # if k < length - 1 t0 = 1
beq $t0, $zero, breakOuterLoop # k >= (length - 1)
add $t9, $zero, $t5 # t9 is min = k
addi $t1, $t5, 1 # t1 is j = k + 1
innerLoop: slt $t0, $t1, $t7 # if j < length t0 = 1
beq $t0, $zero, breakInnerLoop
add $s3, $t9, $t9 # s3 = 2 * min
add $s3, $s3, $s3 # s3 = 4 * min
add $s3, $a0, $s3 # s3 is address of list[min]
lw $t2, 0($s3) # t2 is list[min]
add $s0, $t1, $t1 # s0 = 2 * j
add $s0, $s0, $s0 # s0 = 4 * j
add $s0, $a0, $s0 # s0 is address of list[j]
lw $t3, 0($s0) # t3 is list[j]
slt $t0, $t3, $t2 # if list[j] < list[min] t0 = 1
beq $t0, $zero, secondIF # skip min = j & ++j and jump to secondIF
add $t9, $zero, $t1 # min = j
j secondIF
secondIF: beq $t9, $t5, incrementJ # if min != k swap, else goto incrementJ
# BEGIN SWAP :
add $s0, $t9, $t9 # s0 = 2 * min
add $s0, $s0, $s0 # s0 = 4 * min
add $s0, $s0, $a0 # s0 = address of list[min]
lw $t4, 0($s0) # t4 is temp = list[min]
add $s1, $t5, $t5 # s1 = 2 * k
add $s1, $s1, $s1 # s1 = 4 * k
add $s1, $a0, $s1 # s1 = address of list[k]
lw $s3, 0($s1) # s3 = list[k]
sw $s3, 0($s0) # list[min] = list[k]
sw $t4, 0($s1) # list[k] = temp
addi $t1, $t1, 1 # ++j
add $t9, $zero, $t5 # t9 is min = k
# END SWAP
j innerLoop
incrementJ: addi $t1, $t1, 1 # ++j
j innerLoop
breakInnerLoop: addi $t5, $t5, 1 # ++k
j outerLoop
breakOuterLoop:
#Prints the result string
li $v0, 4
la $a0, result
syscall
#Prints the string entered by the user
la $a0, buffer
li $v0, 4
syscall
exitProgram: li $v0, 10 # system call to
syscall # terminate program