home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-18 | 835 b | 31 lines | [TEXT/KAHL] |
- # Bubble sort my telephone number just for fun.
-
- .data
- nums: .word 1, 6, 0, 8, 2, 3, 8, 8, 1, 3, 7
- .align 1
- hnums: .half 1, 6, 0, 8, 2, 3, 8, 8, 1, 3, 7
- bnums: .byte 1, 6, 0, 8, 2, 3, 8, 8, 1, 3, 7
-
- .text
- .globl __start
- __start:
- move $t0 $zero # init outer loop counter
- outer:
- sll $t4 $t0 2 # convert i to byte offset
- addi $t1 $t0 1 # init inner loop counter
- inner:
- sll $t5 $t1 2 # convert j to byte offset
- lw $t2 nums+0($t4) # load nums[i]
- lw $t3 nums+0($t5) # load nums[j]
- bge $t3 $t2 noswap # compare them
- sw $t2 nums+0($t5) # store nums[j] in nums[i]
- sw $t3 nums+0($t4) # store nums[i] in nums[j]
- noswap:
- addi $t1 $t1 1 # increment inner loop counter
- bne $t1 11 inner # loop if less than 11
- addi $t0 $t0 1 # increment outer loop counter
- bne $t0 10 outer # loop if less than 10
-
- li $v0 10 # exit
- syscall
-