[Coco] 6809 example

Robert Gault robert.gault at worldnet.att.net
Sat Jan 17 13:50:04 EST 2004


Robert Gault wrote:
><snip>
> Good example of assembly code, but the least efficient method of 
> sorting. Here is an equivalent version in Disk Basic for comparison.
> 
><snip>

By the way, if anyone has any doubts on just how inefficient a bubble 
sort is, try the following Basic program; a Super Shell sort. See if you 
can convert it to assembly language.

Note that even though the code is more complex, the speed is much much 
faster than the bubble sort. By implication this also means that if 
speed is your primary concern in picking a language, think again! The 
algorithm and quality of coding can be more important than the language.

10 WIDTH32:FOR I=0TO511:POKEI+&H400,RND(0)*10+48:NEXT
20 REM SUPER SHELL SORT
30 D=INT(2^INT(LOG(512)/LOG(2))-1)
40 FOR I=1 TO 512-D
50 A=PEEK(I+&H3FF):B=PEEK(I+D+&H3FF):IFA<=B THEN 130
60 POKE I+D+&H3FF,A
70 IF I<=D THEN POKE I+&H3FF,B:GOTO130
80 FOR J=I-D TO 1 STEP -D
90 C=PEEK(J+&H3FF):IF B>=C THEN 120
100 POKE(J+D+&H3FF),C
110 NEXTJ
120 POKE(J+D+&H3FF),B
130 NEXTI
140 D=INT(D/2):IF D>0THEN40
150 GOTO150






More information about the Coco mailing list