
 1000  *--------------------------------
 1010  *      BUBBLE-SORT DEMO
 1020  *--------------------------------
 1030  LIST   .EQ $00 THRU $0F
 1040  N      .EQ 16
 1050  FLAG   .EQ $10
 1060  *--------------------------------
 1070  BUBBLE LDY #0       INITIAL INDEX
 1080         STY FLAG     INTERCHANGE FLAG
 1090  .1     LDA LIST+1,Y COMPARE TWO ADJACENT ITEMS
 1100         CMP LIST,Y
 1110         BCS .2       ALREADY IN CORRECT ORDER
 1120         PHA          INTERCHANGE THEM
 1130         LDA LIST,Y
 1140         STA LIST+1,Y
 1150         PLA
 1160         STA LIST,Y
 1170         LDA #$FF     SET INTERCHANGE FLAG
 1180         STA FLAG
 1190  .2     INY          NEXT OVERLAPPING PAIR
 1200         CPY #N-1
 1210         BCC .1       STILL A PAIR LEFT
 1220         LDA FLAG     WAS AN INTERCHANGE PERFORMED?
 1230         BNE BUBBLE   YES, MAKE ANOTHER PASS
 1240         RTS          NO, ALL SORTED

