我一直在练习我的MIPS编程技巧,以及参加计算机架构课程,我遇到了一个问题。这些是说明:写一个MIPS程序:
这是我到目前为止所做的,但我不知道如何使用降序编号填充数组3
.data
array: .space 100
input: .asciiz "Enter at least 4 integers: Enter the number 999 to exit \n"
output: .asciiz "The array in ascending order: \n"
commas: .asciiz ","
.text
.globl main
main:
la $a1, array #loads a pointer to array into $a1
li $a2,9 #loads 9 into $a2
li $t0,0
li $t1,999
loops:
la $a0, input #loads input text into $a
li $v0, 4 #loads 4 into $v0 (prints string)
syscall
li $v0, 5 #loads 5 into $v0 (read interger)
syscall
beq $v0,$t1,swap
addi $t0,$t0,4 #add 4 to $t0, save to $t0
sw $v0, ($a1) #stores input into array
addi $a1, $a1,4 #add 4 to $a1, save to $a1
j loops
swap:
la $t4, array #loads array to $t4
la $t1, array #loads array to $t1
addi $t1,$t1,4 #add 4 to $t1, save to $t1
la $t8,array #loads array to $t8
add $t8,$t0,$t8 #add $t8 to $t0, save to $t8
la $t9,array
add $t9,$t0,$t9 #add $t9 to $t0, save to $t9
addi $t9,$t9,-4 #subtracts 4 from $t9, save to $t9
loop:
lw $t2,($t4) #load input into $t2
lw $t3,($t1) #load input into $t3
bgt $t2,$t3,loop1 #if $t2 > $t3, go to loops
#blt $t2,$t3,loop1 #if $t2 < $t3, go to loops
sw $t3,($t4) #store $t3 in $t4
sw $t2,($t1) #store $t2 in $t1
loop1:
addi $t1,$t1,4 #add 4 to $t1, save to $t1
blt $t1,$t8,loop #if $t1<$t8, go to loop
addi $t4,$t4,4 #add 4 to $t4, save to $t4
move $t1,$t4
addi $t1,$t1,4 #add 4 to $t1, save to $t1
blt $t4,$t9,loop #if $t4<$t9, to go loop
print:
la $a1,array #loads array to $a1
la $a0, output #loads output to $a0
li $v0, 4 #loads 4 into #v0
syscall
loop2:
blez $t0, done #if $t0<=0, go to done
li $v0, 1 #loads 1 into $v0
lw $a0, 0($a1) #load an inout into $a0
syscall
la $a0, commas #loads commas into $a0
li $v0, 4 #loads 4 into $v0
syscall
addi $a1, $a1, 4 #add 4 to $a1, save to $a1
addi $t0, $t0, -4 #subtracts 4 from #t0, save to $t0
j loop2
done:
j done
有人可以帮帮我吗?
P.S。那些评论作为我自己的指南