【发布时间】:2016-08-15 11:53:14
【问题描述】:
我正在尝试在 MIPS MARS 4.5 中进行插入排序。
我遇到了一些麻烦:
答:
lw myArray($s4), myArray($s6)# alist[position] = alist[position-1]
乙:
lw myArray($s4), $s5 # alist[position] = current value
我遇到的问题分别是“操作数过多或格式不正确”和“myArray 操作数的类型不正确”。
基本上我在评论中提到了我想要对展览 A 做的事情,我试图让 myArray($s4) = myArray($s6),但它不会让我 lw/la 和我'也尝试过添加以将其移入。
对于展览 B,我想将 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:
【问题讨论】: