<<<--- % Pratts Sort % 5.2.1 Exercise 31 % improved setting m lower % Martin Ruckert, 27.4.2012 % PREFIX :Ssort: :Ssort IS @ --->>> R IS $0 & Parameter n IS $1 H IS $2 t IS $3 s IS $4 & Local variables j IS $5 i IS $6 Kj IS $7 Ki IS $8 Rh IS $9 Rn IS $10 d IS $11 h IS $12 m IS $13 tmp IS $14 Prattsort SL n,n,3 \hfil$1$& $n \is \hbox{\rm size in byte}$. ADD Rn,R,n \hfil$1$& Address of $R_n$. SL s,t,3 \hfil$1$& \ul{\sl D1.~Loop on $s$.} JMP 1F \hfil$1$ 2H LDO h,H,s \hfil$T$& \ul{\sl D2.~Loop on $j$.} SL h,h,3 \hfil$T$ SUB Rh,Rn,h \hfil$T$& $\.{Rh} \is \mathop{\hbox{Address~of}} R_{n-h}$. SET m,h SL tmp,m,1 CMP tmp,tmp,n BNP tmp,0F SUB m,n,h JMP 0F \hfil$T$& <<<--- --->>> 3H LDO Kj,Rn,j \hfil$NT-S-B+A$& Load and compare $K_j : K_{j-h}$. LDO Ki,Rh,j \hfil$NT-S-B+A$& CMP tmp,Kj,Ki \hfil$NT-S-B+A$& PBNN tmp,7F \hfil$NT-S-B+A+2B$& If $K_j \ge K_{j-h}$ jump to increment $j$. STO Ki,Rn,j \hfil$B$& Exchange $K_j$ and $K_{j-h}$. STO Kj,Rh,j \hfil$B$& ADD j,j,h \hfil$B$& Increment $j$. 7H ADD j,j,h \hfil$NT-S-B+A$& Increment $j$. PBN j,3B 0H SUB m,m,8 \hfil$S$ SUB j,m,n \hfil$S$ & $j \is m$. PBNN m,7B <<<--- --->>> 1H SUB s,s,8 \hfil$T+1$& Decrement $s$. PBNN s,2B \hfil$T+3$& $0\le s < t$ POP 0,0 <<<--- PREFIX : --->>>