.data
arr:.word 49,38,65,97,76,13,27
ai:.asciiz "xxxxxx"
nl:.asciiz "\n".text
main:
la $t0,arr
li $t1,0 # i
li $t2,0 # j
li $t3,6 #len-1
li $t4,4
loop1:
bgt $t1,$t3,out
mul $t5,$t4,$t1 #tmp
lw $t9,($t5) #min
move $t7,$t9
addi $t2,$t1,1
loop2:
bgt $t2,$t3,loop1_end
mul $t5,$t4,$t2
lw $t6,($t5)
bgt $t6,$t7,unexchange
li $s1,1
move $t7,$t6
add $s0,$zero,$t2
mul $s0,$s0,4
unexchange:
addi $t2,$t2,1
b loop2
loop1_end:
beqz $s1,loop1_jump_unchanged
mul $t8,$t4,$t1
sw $t7,($t8)
sw $t9,($s0)
loop1_jump_unchanged:
addi $t1,$t1,1
li $s1,0
b loop1
out:
la $t0,arr
print:
bgt $t0,$t3,out2
mul $t1,$t4,$t0
lw $t5,arr($t1)
li $v0,1
move $a0,$t5
syscall
li $v0,4
la $a0,nl
syscall
addi $t0,$t0,1
b print
out2:
li $v0,10
syscall
【MIPS汇编简单算法实例 Lab8】选择排序法.data arr:.word 49,38,65,97,76,13,27 ai:.asciiz "xxxxxx" nl:.asciiz "\n".text main: la $t0,arr li $t1,0 # i li $t2,0 # j li $t3,6 #len-1 li $t4,4 loop1: bgt $t1,$t3,out mul $t5,$t4,$t1 #tmp lw $t9,($t5) #min