home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / SPIM Folder / Examples / bsort.s next >
Encoding:
Text File  |  1993-01-18  |  835 b   |  31 lines  |  [TEXT/KAHL]

  1. # Bubble sort my telephone number just for fun.
  2.  
  3.     .data
  4. nums:    .word 1, 6, 0, 8, 2, 3, 8, 8, 1, 3, 7
  5.     .align 1
  6. hnums:    .half 1, 6, 0, 8, 2, 3, 8, 8, 1, 3, 7
  7. bnums:  .byte 1, 6, 0, 8, 2, 3, 8, 8, 1, 3, 7
  8.  
  9.     .text
  10.     .globl __start
  11. __start:
  12.     move $t0 $zero        # init outer loop counter
  13. outer:
  14.     sll $t4 $t0 2        # convert i to byte offset
  15.     addi $t1 $t0 1        # init inner loop counter
  16. inner:
  17.     sll $t5 $t1 2        # convert j to byte offset
  18.     lw $t2 nums+0($t4)    # load nums[i]
  19.     lw $t3 nums+0($t5)    # load nums[j]
  20.     bge $t3 $t2 noswap    # compare them
  21.     sw $t2 nums+0($t5)    # store nums[j] in nums[i]
  22.     sw $t3 nums+0($t4)    # store nums[i] in nums[j]
  23. noswap:    
  24.     addi $t1 $t1 1        # increment inner loop counter
  25.     bne $t1 11 inner    # loop if less than 11
  26.     addi $t0 $t0 1        # increment outer loop counter
  27.     bne $t0 10 outer    # loop if less than 10
  28.  
  29.     li $v0 10        # exit
  30.     syscall
  31.