# Second SPIM assignment # Perform bubblesort in memory. # Program 2 # Name: Peter Woodman # Class: CSE410 # Date: 04142005 .data #array: .word 4 15 8 39 1 #length: .word 5 array: .word 10 9 8 7 6 5 4 3 2 1 length: .word 10 .globl main .text # the program segment. main: la $t0, array # load array address into t0 ulw $t1,length # load length from pointer addi $t1,$t1,-1 # knock one off the length addi $t2,$zero,0 # initialize counter loop1: addi $t3,$zero,0 # (re)init counter loop2: sll $t4,$t3,2 # shift to words add $t4,$t0,$t4 # add array address lw $t5,0($t4) # load... lw $t6,4($t4) # ...elements ble $t5,$t6,jumpto # compare sw $t6,0($t4) # switch... sw $t5,4($t4) # ...positions jumpto: addi $t3,$t3,1 # increment inner count blt $t3,$t1,loop2 # jump back if not past count # close inner loop addi $t2,$t2,1 # increment outer count blt $t2,$t1,loop1 # jump back if not past count # end program