[Coco] 6809 example

Robert Gault robert.gault at worldnet.att.net
Sat Jan 17 08:18:45 EST 2004


Roger Taylor wrote:
> 
> The first ML program I ever typed in and saw run was, in fact, the 
> bubble sort example from William Barden's 6809 Assembly Language 
> Programming book. <snip>

> ----------
> Roger Taylor
> 
> 
> 
> 

Good example of assembly code, but the least efficient method of 
sorting. Here is an equivalent version in Disk Basic for comparison.

10 WIDTH32: FOR I=0TO511:POKEI+&H400,RND(0)*9+48:NEXT
20 REM BUBBLE SORT
30 FORX=&H400 TO &H5FE
40 A=PEEK(X):B=PEEK(X+1):IF B>A THEN POKEX,B:POKEX+1,A:Y=1
60 NEXT
70 PASS=PASS+1
80 IF Y<>0 THEN 30
90 GOTO 90

With this version when all action stops, hit the BREAK key and PRINT 
PASS. With Roger's example it will not be quite as easy to examine the 
pass counter.

It is interesting that in this example, assembly code is almost as easy 
to write and almost as short as Basic. That is because the tasks 
involved are ideal for assembly code. For only slightly more complex 
tasks, the size of the assembly code will balloon significantly vs Basic.




More information about the Coco mailing list