我試圖在MIPS MARS 4.5中進行插入排序。將數組值加載到另一個數組值
我有一些麻煩特別是與:
答:
lw myArray($s4), myArray($s6)# alist[position] = alist[position-1]
B:
lw myArray($s4), $s5 # alist[position] = current value
我得到的問題是,「太多或不正確格式化操作數「和」myArray操作數的類型不正確「。
基本上我試圖做與展覽A在評論中提到,我試圖讓myArray($ s4)= myArray($ s6),但它不會讓我lw/la和我也試過添加到其移動英寸
展品BI要更改myArray的($ S4)的值將在$ S5值
任何人能幫助我經營我應該在這裏使用? 謝謝
我已經鏈接了以下功能的其餘部分以防萬一需要。
再次感謝。
sort:
addi $sp, $sp, -32 # save values on stack
sw $ra, 0($sp) # Store the saved values on the stack to restore when done
sw $s0, 4($sp) # s0 = base address of array
sw $s1, 8($sp) # s1 = size of array
sw $s2, 12($sp) # s2 = i
sw $s3, 16($sp) # s3 = j
sw $s4, 20($sp) # s4 = position
sw $s5, 24($sp) # s5 = currentvalue
sw $s6, 28($sp) # s6 = position - 1
la $a0, myArray # load array address into a0
la $a1, myArray($s2) # load size of array into a1
move $s0, $a0 # move array address into s0
move $s1, $a1 # move size of array into s1
li $s2, 0 # set i to 0
li $s3, 0 # set j to 0
li $t0, 0 # set t0 to 0
iloop:
# if s1 >= size of array go to end
slt $t5, $s2, $s1 # check if a1 > s2
beq $t5, 0, endWhile # if it is, jump to the end
lw $s5, myArray($s2) # currentvalue = alist[i]
add $s4, $zero, $s2 # position = i
sub $s6, $s4, 4 # position - 1
j jloop # else go to jloop
jloop:
# if position is <= 0
slt $t5, $s4, $t0 # check if s4 is greater than 0
beq $t5, 0, iloop # if its less, jump to the end
# and alist[position-1] < currentvalue
slt $t5, $s6, $s5 # check if alist[position-1] > current value
beq $t5, 0, iloop # if less than jump back to iloop
lw myArray($s4), myArray($s6)# alist[position] = alist[position-1]
sub $s4, $s4, 1 # position = position - 1
j setArray
setArray:
lw myArray($s4), $s5 # alist[position] = current value
j iloop
endWhile: