home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / asm / AsmSort.lha / _BubbleSort.s next >
Encoding:
Text File  |  1997-01-22  |  593 b   |  44 lines

  1.  
  2. ; Bubble sort in MC68020+ ASM.
  3. ; (c) Mattias Nilsson (c-lous@freenet.hut.fi)
  4. ;
  5. ; Sorts an array of 16 bit INTS.
  6.  
  7. ListSize    =    256
  8.  
  9.     xdef    _BubbleSort
  10.  
  11.  
  12. _BubbleSort:
  13.  
  14. ; Create some "random" numbers
  15.     Lea.l    List(Pc),a0
  16.     Move.l    #ListSize-1,d7
  17. .Loop:    Move.w    $dff006,d0
  18.     Muls    d7,d0
  19.     Lsr.w    #7,d0
  20.     Move.w    d0,(a0)+
  21.     Dbf    d7,.Loop
  22.  
  23.     
  24. ; Bubble sort the array.
  25.  
  26. .BubbleSort:
  27.     Move.l    a1,a0
  28.     Move.l    d2,d0
  29.     clr.w    d1
  30. Loop:    move.b    1(a0),d3
  31.     cmp.b    (a0)+,d3
  32.     bcc.s    .noswap
  33.     move.b    -1(a0),d1
  34.     move.b    (a0),-1(a0)
  35.     move.b    d1,(a0)
  36.     bset    #0,d1
  37.  
  38. .noswap:dbf    d0,Loop
  39.     tst.w    d1
  40.     bne.s    .BubbleSort
  41.     Rts
  42.  
  43. List:    Ds.w    ListSize
  44.