Professional Documents
Culture Documents
data
A: .word 4, -1, 5, 3, -6, -6
.text
la t0,A #t0=*A
li t1,1 #t1=n_trocas=1
li a0,6 #N=a0=6
li a1,4 #a1=sizeofword
for1: #cycle with n_trocas
li t1,0 #t1=n_trocas=0
li t2,1 #t2=i
for2: #cycle with i and N
mul t3,t2,a1 #offset(t3)=i*sizeofword
add t4,t3,t0 #address of A[i]
addi t5,t4,-4 #address of A[i-1]
lw a3,0(t4) #a3=A[i]
lw a2,0(t5) #a2=A[i-1]
bge a3,a2,endif #if (A[i]<A[i-1]) jump to endif
mv a4,a3 #tmp = A[i]
#instead of saving later, the values are changed here, using tmp also
sw a2,0(t4) #A[i-1] -> *A[i]
sw a4,0(t5) #A[i]=tmp -> *A[i-1]
addi t1,t1,1 #n_trocas++
j endif
endif:
addi t2,t2,1 #i++
bne a0,t2,for2 #if (i!=(N=6)) jump to for2
bnez t1,for1 #if (t1!=0) jump to for1