.data data: .word 12:10 ptr: .word nptr: .word i: .word k: .word # don't use j temp: .word prompt: .asciiz "? " nl: .asciiz "\n" .text __start: la ptr, data move i, 10 while1: # read 10 ints beqz i, ewhile1 puts prompt get M[ptr] sub i, i, 1 add ptr, ptr, 4 b while1 ewhile1: move i, 9 while2: # outer loop of bubble sort beqz i, ewhile2 la ptr, data mul temp, 8, 4 add ptr, ptr, temp # ptr points to next to last # element in data move k, i while3: # inner loop of bubble sort beqz k, ewhile3 add nptr, ptr, 4 # nptr points to next element # beyond ptr if1: # compare & swap ble M[ptr], M[nptr], eif1 move temp, M[ptr] move M[ptr], M[nptr] move M[nptr], temp eif1: sub k, k, 1 move nptr, ptr sub ptr, ptr, 4 b while3 ewhile3: sub i, i, 1 b while2 ewhile2: la ptr, data move i, 10 while4: # write 10 ints beqz i, ewhile4 put M[ptr] puts nl sub i, i, 1 add ptr, ptr, 4 b while4 ewhile4: done