1: / 2: / 3: 4: / quicker sort 5: 6: / mov $base,r1 7: / mov $base+[n*width],r2 8: / mov $width,r3 9: / jsr pc,qsort 10: 11: / r0,r1,r2,r3,r4 are used 12: 13: .globl qsort 14: .globl compare 15: 16: qsort: 17: mov r5,-(sp) 18: mov r4,-(sp) 19: bit $1,r3 20: bne 1f 21: bit $1,r1 22: bne 1f 23: cmp r3,$2 24: bne 2f 25: mov $exch1,exchange 26: br 3f 27: 2: 28: mov r3,r5 29: clc 30: ror r5 31: mov r5,width 32: mov $exchw,exchange 33: br 3f 34: 1: 35: mov $exchb,exchange 36: 3: 37: jsr pc,qs1 38: mov (sp)+,r4 39: mov (sp)+,r5 40: rts pc 41: 42: qs1: 43: mov r1,r5 44: neg r5 45: add r2,r5 46: bgt 1f 47: rts pc 48: 1: 49: clr r4 50: dvd r3,r4 51: asr r4 52: mpy r3,r4 53: mov r5,r4 54: add r1,r4 55: 56: mov r1,-(sp) 57: mov r2,-(sp) 58: 59: loop: 60: cmp r1,r4 61: bhis loop1 62: mov r1,r0 63: jsr pc,compare 64: bgt loop1 65: add r3,r1 66: br loop 67: 68: loop1: 69: cmp r2,r4 70: blos 1f 71: sub r3,r2 72: mov r2,r0 73: jsr pc,compare 74: bge loop1 75: 76: jsr pc,*exchange 77: cmp r1,r4 78: bne loop 79: mov r2,r4 80: br loop 81: 82: 1: 83: cmp r1,r4 84: beq 1f 85: jsr pc,*exchange 86: mov r1,r4 87: br loop1 88: 89: 1: 90: mov (sp)+,r2 91: mov r4,-(sp) 92: mov r4,r1 93: add r3,r1 94: mov r2,r0 95: sub r1,r0 96: sub 2(sp),r4 97: cmp r0,r4 98: blo 1f 99: mov (sp)+,r0 100: mov (sp)+,r4 101: mov r1,-(sp) 102: mov r2,-(sp) 103: mov r0,r2 104: mov r4,r1 105: 1: 106: jsr pc,qs1 107: mov (sp)+,r2 108: mov (sp)+,r1 109: br qs1 110: 111: exchb: 112: mov r1,-(sp) 113: mov r2,-(sp) 114: mov r3,r5 115: 1: 116: movb (r1),r0 117: movb (r2),(r1)+ 118: movb r0,(r2)+ 119: sob r5,1b 120: mov (sp)+,r2 121: mov (sp)+,r1 122: rts pc 123: 124: exchw: 125: mov r1,-(sp) 126: mov r2,-(sp) 127: mov width,r5 128: 1: 129: mov (r1),r0 130: mov (r2),(r1)+ 131: mov r0,(r2)+ 132: sob r5,1b 133: mov (sp)+,r2 134: mov (sp)+,r1 135: rts pc 136: 137: exch1: 138: mov (r1),r0 139: mov (r2),(r1) 140: mov r0,(r2) 141: rts pc 142: 143: .bss 144: exchange: .=.+2 145: width: .=.+2