<<<--- % Bubble Sort % 5.2.2 Page 107 % Author Martin Ruckert, 26.3.2012 --->>> R IS $0 &Array of Records (\.{OCTAS}). n IS $1 &Number of Records. Bound IS $1 &Reuseing register for $n$. j IS $3 &Local Variables. rj IS $4 rjj IS $5 t IS $6 tmp IS $7 BubbleSort SUB n,n,1; 8ADDU Bound,n,R \hfil$2$&\ul{\sl B1.~Initialize \.{Bound}.} JMP 2F \hfil$1$& 3H LDO rj,Bound,j \hfil$A$&\ul{\sl B3.~Compare/exchange $R_j:R_{j+1}$.} Loop ADD j,j,8 \hfil$C$& LDO rjj,Bound,j \hfil$C$& CMP tmp,rj,rjj \hfil$C$&$K_j>K_{j+1}$ ? PBNP tmp,0F \hfil$C+2B$& STO rj,Bound,j \hfil$B$&Interchange $R_j \leftrightarrow R_{j+1}$. SUB t,j,8 \hfil$B$&$t \is j$ STO rjj,Bound,t \hfil$B$& PBN j,Loop \hfil$B+2D$& JMP 4F \hfil$D$& 0H SET rj,rjj \hfil$C-B$& PBN j,Loop \hfil$C-B+2(A-D)$& 4H BZ t,End \hfil$A+2$&\ul{\sl B4.~Any exchanges?} $t\is 0$ ADD Bound,Bound,t \hfil$A-1$&$\.{Bound}\is t$ 2H SET t,0 \hfil$A$&\ul{\sl B2.~Loop on $j$.} $t\is 0$ SUB j,R,Bound \hfil$A$&$j\is 0$ PBN j,3B \hfil$A$&$j = 0, 1, \ldots , \.{Bound}-1$ End POP 0,0