mips冒泡排序程序
.data
a: .word 5, 4, 7, 8, 1
N: .word 5
.text
la $s1, a
li $t0, 0
lw $s2, N
loop:
bge $t0, $s2, end
li $t1, 0
loop2:
sub $s3, $s2, $t0
subi $s3, $s3, 1 # N-i-1
bge $t1, $s3, end2
sll $t2, $t1, 2
add $t2, $s1, $t2 #a[j]
lw $t3, ($t2)
addi $t4, $t1, 1 # t4 = j+1
sll $t4, $t4, 2
add $t4, $s1, $t4 # a[j+1]
lw $t5, ($t4)
bgt $t3, $t5, swap
j next
swap:
sw $t5, ($t2)
sw $t3, ($t4)
next:
addi $t1, $t1, 1
j loop2
end2:
addi $t0, $t0, 1
j loop
end:
li $t1, 0
loop3:
bge $t1, $s2, end3
sll $t2, $t1, 2
add $t2, $s1, $t2 #a[j]
lw $a0, ($t2)
li $v0, 1
syscall
li $a0, ' '
li $v0, 11
syscall
addi $t1, $t1, 1
j loop3
end3:
li $v0, 10
syscall