.TITLE BUBBLESORT .GLOBL WRITED,WRITEC,READD,EXIT ; This example SUPERMAC program will perform a simple ; bubble sort. The variable COUNT indicates how many ; values to sort. ; Program declarations K: .BLKW 1 OUT: .BLKW 1 TMP: .BLKW 1 NM: .BLKW 1 COUNT: .BLKW 1 FLAG: .BLKW 1 NUM: .BLKW 100. MESS0: .ASCII/ Please input each of your values followed by a/ .ASCIZ/ for each of the numbers./ <15><12><7><7> MESS1: .ASCIZ/ How many elements do you wish to sort? / <15><12><7><7> MESS2: .ASCIZ/ The sorted numbers are as follow ... / <15><12> .EVEN ; The actual program now begins BEGIN: PRINT MESS1 READLN COUNT PRINT MESS0 LET R0 := #NUM FOR K := #1 TO COUNT READLN NM LET (R0)+ := NM END ; The above code reads in the values to be sorted. LET FLAG := #0 LET R3 := #COUNT LET R3 := (R3) - #1 WHILE FLAG = #0 DO LET R0 := #NUM LET FLAG := #1 ; Set up conditions, now perform sort .... FOR K := #1 TO R3 LET R1 := R0 + #2 IF (R0) > (R1) THEN LET TMP := (R0) LET (R0) := (R1) LET (R1) := TMP LET FLAG := #0 FI LET R0 := R0 + #2 END ; of the for loop END ; of the while loop ; Finally, output the results PRINT MESS2 LET R1 := #NUM LET R3 := R3 + #1 FOR K := #1 TO R3 LET OUT := (R1)+ WRITELN OUT END .EXIT .END BEGIN