Home » Archimedes archive » Archimedes World » AW-1995-05-Disc1.adf » AWMay95_1 » InTheMag/AcornAns/FastFastDv
InTheMag/AcornAns/FastFastDv
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Archimedes World » AW-1995-05-Disc1.adf » AWMay95_1 |
Filename: | InTheMag/AcornAns/FastFastDv |
Read OK: | ✔ |
File size: | 0E8A bytes |
Load address: | 0000 |
Exec address: | 0000 |
Duplicates
There is 1 duplicate copy of this file in the archive:
- Archimedes archive » Archimedes World » AW-1996-03-Disc 2.adf » !AcornAns_AcornAns » September/FastDiv/FastFastDv
- Archimedes archive » Archimedes World » AW-1995-05-Disc1.adf » AWMay95_1 » InTheMag/AcornAns/FastFastDv
File contents
10REM >FastFastDv 20REM Fast DIV/MOD with a constant number 30REM code fragment to test fastdiv/mod code generation 40REM Author of code generator: Michael Rozdoba, based on algorithm 50REM of initial design by: Samuel K.R. Smith 60REM further modified by: Michael Rozdoba 70 80ONERROR:PROCerr:END 90MODE 0 100 110spoolpath$ = "FFDdemo" 120spool%=FALSE 130IF spool% OSCLI("Spool "+spoolpath$) 140 150PRINT '"Fast Integer Division Code for arbitrary CONSTANT Divisor -" 160PRINT "Compilation & testing:"' 170PRINT "This program lists the divisors it is testing & disassembles each routine," 180PRINT "each of which calculates R0 = R2 DIV divisor, R1 = R2 MOD divisor." 190PRINT "If it finds an error it prints the details and waits for a key press."'' 200 210REM Load generator code 220SYS "OS_File", 5, "Generator.Generator" TO gentyp%,,,,genlen% 230IF gentyp%<>1 ERROR 1, "Generator code file not found" 240DIM generator% genlen% 250SYS "OS_File", 255, "Generator.Generator", generator%, 0 260 270DIM code% &400 280r0=0:r1=1:r2=2:r3=3 290 300Q%=1000 310R%=&7FFFFFFF-Q% 320S%=&80000000+Q% 330maxc%=0: nmaxc%=0: totc%=0: cnt%=0 340 350Zbase%=1 360Zrange%=100000 370 380Z%=Zbase% 390REPEAT 400 PROCcheck( Z%,-Q%,Q%, 1) 410 PROCcheck(-Z%,-Q%,Q%, 2) 420 PROCcheck( Z%,R%,&7FFFFFFF, 0) 430 PROCcheck(-Z%,R%,&7FFFFFFF, 0) 440 PROCcheck( Z%,&80000000,S%, 0) 450 PROCcheck(-Z%,&80000000,S%, 0) 460 PROCcheck( Z%,-Q%,Q%, 100+0) 470 PROCcheck(-Z%,-Q%,Q%, 100-1) 480 cnt% += 1 490 l% =(aft%-fore%)/4 500 totc% += l% 510 IF l%>maxc% THEN 520 maxc% = l% 530 nmaxc%= Z% 540 ENDIF 550 PRINT"Current max code length ";maxc%;" instructions for divisor ";FNnstr(nmaxc%) 560 PRINT"Average code length ";totc%/cnt%;" instructions"'' 570Z%+=1 580UNTIL Z%=Zbase%+Zrange% 590ERROR 1, "All done" 600 610END 620 630DEFPROCcheck(N%,START%,FINISH%, report%) 640LOCAL l%, rnd% 650PROCasstst(N%):REM produce the code then test it! 660 670IF report%>50 rnd%=TRUE:report%-=100 ELSE rnd%=FALSE 680IF report% < 1 PRINT ;", ";FNnstr(N%); 690IF report% =-1 PRINT 700IF report%=1 THEN 710 PRINT"Checking division by &";~N%;" = ";N% 720 l% =(aft%-fore%)/4 730 PRINT"Using code, length ";l%;" instructions:" 740 PROCdis(fore%, aft%) 750ENDIF 760IF report%=2 PRINT"Further checks for ";FNnstr(N%); 770 780IF rnd% A%=RND(-1) 790FOR F%=START% TO FINISH% STEP 1 800 IF rnd% THEN 810 IF RND(2)=1 C%=RND(&7FFFFFFF)-&40000000 ELSE C%=RND(&0007FFFF)-&00040000 820 ELSE 830 C%=F% 840 ENDIF 850 A%=USR(code%):B%=!r% 860 D%=C% DIV N%:E%=C% MOD N% 870 IF (A%<>D%)OR(B%<>E%) THEN 880 PRINT"Error Found: ";~C%;" DIV ";~N%;"=";~A%;" "; 890 PRINT;~C%;" MOD ";~N%;"=";~B%;" should be ";~D%;" and ";~E% 900 IF spool%=FALSE G=GET 910 ENDIF 920NEXT 930ENDPROC 940 950DEFPROCasstst(n%) 960r0=0:r1=1:r2=2:r3=3:r4=4:r5=5:lr=14 970 980REM require workReg if n% can't be expressed as a valid immediate const 990workR=r4 1000 1010signpresR=r3 1020 1030FOR pass%=0 TO 2 STEP 2 1040P%=code% 1050[ OPT pass% 1060.fore% OPT FNFastDiv(r0,r1,r2,n%,signpresR,workR,pass%) 1070.aft% STR r1,r% 1080 MOV pc,lr 1090.r% EQUD 0 1100] 1110NEXT 1120ENDPROC 1130 1140DEF FNFastDiv(outq%, outr%, num%, const%, signpres%, work%, pass%) 1150LOCAL len% 1160A% = const% 1170B% = P% 1180C% = num% 1190D% = outq% 1200E% = outr% 1210F% = work% 1220G% = signpres% 1230len% = USR generator% 1240IF len%<0 ERROR 1, "Generator call has failed, code "+STR$(len%) 1250P% += len% 1260 = pass% 1270 1280DEF PROCdis(a%, b%) 1290LOCAL q%, w%, q$, i% 1300FOR q%=a% TO b%-1 STEP 4 1310 SYS &40380, !q%, q% TO ,x%,y% 1320 q$="" 1330 FOR w%=x% TO x%+y%-1 1340 q$+=CHR$(?w%) 1350 NEXT 1360 i% = INSTR(q$, ";") 1370 IF i%>1 THEN 1380 FOR w%=i%-1 TO 1 STEP -1 1390 IF MID$(q$, w%, 1) <> " " THEN 1400 q$ = LEFT$(q$, w%) 1410 w%=0 1420 ENDIF 1430 NEXT 1440 ENDIF 1450 PRINT q$ 1460NEXT 1470ENDPROC 1480 1490DEF FNnstr(n%) 1500IF ABS(n%)<65536 THEN 1510 = STR$(n%) 1520ELSE 1530 = "&"+STR$~(n%) 1540ENDIF 1550 1560DEF PROCerr 1570ON ERROR OFF 1580REPORT:PRINT" with code: ";ERL/10 1590IF spool% THEN 1600 *Spool 1610 spool%=FALSE 1620 OSCLI("SetType "+spoolpath$+" Text") 1630ENDIF 1640ENDPROC
� >FastFastDv )� Fast DIV/MOD with a constant number 7� code fragment to test fastdiv/mod code generation (C� Author of code generator: Michael Rozdoba, based on algorithm 21� of initial design by: Samuel K.R. Smith </� further modified by: Michael Rozdoba F P �:�err:� Z� 0 d nspoolpath$ = "FFDdemo" xspool%=� �#� spool% �("Spool "+spoolpath$) � �D� '"Fast Integer Division Code for arbitrary CONSTANT Divisor -" �� "Compilation & testing:"' �R� "This program lists the divisors it is testing & disassembles each routine," �J� "each of which calculates R0 = R2 DIV divisor, R1 = R2 MOD divisor." �O� "If it finds an error it prints the details and waits for a key press."'' � �� Load generator code �Aș "OS_File", 5, "Generator.Generator" � gentyp%,,,,genlen% �5� gentyp%<>1 � 1, "Generator code file not found" �� generator% genlen% �;ș "OS_File", 255, "Generator.Generator", generator%, 0 � code% &400 r0=0:r1=1:r2=2:r3=3 " ,Q%=1000 6R%=&7FFFFFFF-Q% @S%=&80000000+Q% J&maxc%=0: nmaxc%=0: totc%=0: cnt%=0 T ^Zbase%=1 hZrange%=100000 r | Z%=Zbase% �� � �check( Z%,-Q%,Q%, 1) � �check(-Z%,-Q%,Q%, 2) �! �check( Z%,R%,&7FFFFFFF, 0) �! �check(-Z%,R%,&7FFFFFFF, 0) �! �check( Z%,&80000000,S%, 0) �! �check(-Z%,&80000000,S%, 0) � �check( Z%,-Q%,Q%, 100+0) � �check(-Z%,-Q%,Q%, 100-1) � cnt% += 1 � l% =(aft%-fore%)/4 � totc% += l% � � l%>maxc% � maxc% = l% nmaxc%= Z% � &R �"Current max code length ";maxc%;" instructions for divisor ";�nstr(nmaxc%) 0: �"Average code length ";totc%/cnt%;" instructions"'' : Z%+=1 D� Z%=Zbase%+Zrange% N� 1, "All done" X b� l v'��check(N%,START%,FINISH%, report%) �� l%, rnd% �0�asstst(N%):� produce the code then test it! � �-� report%>50 rnd%=�:report%-=100 � rnd%=� �$� report% < 1 � ;", ";�nstr(N%); �� report% =-1 � �� report%=1 � �, �"Checking division by &";~N%;" = ";N% � l% =(aft%-fore%)/4 �0 �"Using code, length ";l%;" instructions:" � �dis(fore%, aft%) �� �1� report%=2 �"Further checks for ";�nstr(N%); � rnd% A%=�(-1) � F%=START% � FINISH% � 1 � rnd% � *F � �(2)=1 C%=�(&7FFFFFFF)-&40000000 � C%=�(&0007FFFF)-&00040000 4 � > C%=F% H � R A%=�(code%):B%=!r% \ D%=C% � N%:E%=C% � N% f � (A%<>D%)�(B%<>E%) � p6 �"Error Found: ";~C%;" DIV ";~N%;"=";~A%;" "; z@ �;~C%;" MOD ";~N%;"=";~B%;" should be ";~D%;" and ";~E% � � spool%=� G=� � � �� �� � ���asstst(n%) �'r0=0:r1=1:r2=2:r3=3:r4=4:r5=5:lr=14 � �I� require workReg if n% can't be expressed as a valid immediate const �workR=r4 � �signpresR=r3 � � pass%=0 � 2 � 2 P%=code% [ OPT pass% $>.fore% OPT �FastDiv(r0,r1,r2,n%,signpresR,workR,pass%) ..aft% STR r1,r% 8 MOV pc,lr B.r% EQUD 0 L] V� `� j tC� �FastDiv(outq%, outr%, num%, const%, signpres%, work%, pass%) ~ � len% �A% = const% � B% = P% �C% = num% �D% = outq% �E% = outr% �F% = work% �G% = signpres% �len% = � generator% �<� len%<0 � 1, "Generator call has failed, code "+�(len%) �P% += len% � = pass% � � �dis(a%, b%) � q%, w%, q$, i% � q%=a% � b%-1 � 4 ș &40380, !q%, q% � ,x%,y% ( q$="" 2 � w%=x% � x%+y%-1 < q$+=�(?w%) F � P i% = �q$, ";") Z � i%>1 � d � w%=i%-1 � 1 � -1 n � �q$, w%, 1) <> " " � x q$ = �q$, w%) � w%=0 � � � � � � � � q$ �� �� � �� �nstr(n%) �� �(n%)<65536 � � = �(n%) �� � = "&"+�~(n%) � � �err " � � � ,�:�" with code: ";�/10 6� spool% � @ *Spool J spool%=� T% �("SetType "+spoolpath$+" Text") ^� h� �
00000000 0d 00 0a 11 f4 20 3e 46 61 73 74 46 61 73 74 44 |..... >FastFastD| 00000010 76 0d 00 14 29 f4 20 46 61 73 74 20 44 49 56 2f |v...). Fast DIV/| 00000020 4d 4f 44 20 77 69 74 68 20 61 20 63 6f 6e 73 74 |MOD with a const| 00000030 61 6e 74 20 6e 75 6d 62 65 72 0d 00 1e 37 f4 20 |ant number...7. | 00000040 63 6f 64 65 20 66 72 61 67 6d 65 6e 74 20 74 6f |code fragment to| 00000050 20 74 65 73 74 20 66 61 73 74 64 69 76 2f 6d 6f | test fastdiv/mo| 00000060 64 20 63 6f 64 65 20 67 65 6e 65 72 61 74 69 6f |d code generatio| 00000070 6e 0d 00 28 43 f4 20 41 75 74 68 6f 72 20 6f 66 |n..(C. Author of| 00000080 20 63 6f 64 65 20 67 65 6e 65 72 61 74 6f 72 3a | code generator:| 00000090 20 4d 69 63 68 61 65 6c 20 52 6f 7a 64 6f 62 61 | Michael Rozdoba| 000000a0 2c 20 62 61 73 65 64 20 6f 6e 20 61 6c 67 6f 72 |, based on algor| 000000b0 69 74 68 6d 0d 00 32 31 f4 20 20 20 20 20 6f 66 |ithm..21. of| 000000c0 20 69 6e 69 74 69 61 6c 20 64 65 73 69 67 6e 20 | initial design | 000000d0 62 79 3a 20 53 61 6d 75 65 6c 20 4b 2e 52 2e 20 |by: Samuel K.R. | 000000e0 53 6d 69 74 68 0d 00 3c 2f f4 20 20 20 20 20 20 |Smith..</. | 000000f0 66 75 72 74 68 65 72 20 6d 6f 64 69 66 69 65 64 |further modified| 00000100 20 62 79 3a 20 4d 69 63 68 61 65 6c 20 52 6f 7a | by: Michael Roz| 00000110 64 6f 62 61 0d 00 46 04 0d 00 50 0d ee 85 3a f2 |doba..F...P...:.| 00000120 65 72 72 3a e0 0d 00 5a 07 eb 20 30 0d 00 64 04 |err:...Z.. 0..d.| 00000130 0d 00 6e 1a 73 70 6f 6f 6c 70 61 74 68 24 20 3d |..n.spoolpath$ =| 00000140 20 22 46 46 44 64 65 6d 6f 22 0d 00 78 0c 73 70 | "FFDdemo"..x.sp| 00000150 6f 6f 6c 25 3d a3 0d 00 82 23 e7 20 73 70 6f 6f |ool%=....#. spoo| 00000160 6c 25 20 ff 28 22 53 70 6f 6f 6c 20 22 2b 73 70 |l% .("Spool "+sp| 00000170 6f 6f 6c 70 61 74 68 24 29 0d 00 8c 04 0d 00 96 |oolpath$).......| 00000180 44 f1 20 27 22 46 61 73 74 20 49 6e 74 65 67 65 |D. '"Fast Intege| 00000190 72 20 44 69 76 69 73 69 6f 6e 20 43 6f 64 65 20 |r Division Code | 000001a0 66 6f 72 20 61 72 62 69 74 72 61 72 79 20 43 4f |for arbitrary CO| 000001b0 4e 53 54 41 4e 54 20 44 69 76 69 73 6f 72 20 2d |NSTANT Divisor -| 000001c0 22 0d 00 a0 1f f1 20 22 43 6f 6d 70 69 6c 61 74 |"..... "Compilat| 000001d0 69 6f 6e 20 26 20 74 65 73 74 69 6e 67 3a 22 27 |ion & testing:"'| 000001e0 0d 00 aa 52 f1 20 22 54 68 69 73 20 70 72 6f 67 |...R. "This prog| 000001f0 72 61 6d 20 6c 69 73 74 73 20 74 68 65 20 64 69 |ram lists the di| 00000200 76 69 73 6f 72 73 20 69 74 20 69 73 20 74 65 73 |visors it is tes| 00000210 74 69 6e 67 20 26 20 64 69 73 61 73 73 65 6d 62 |ting & disassemb| 00000220 6c 65 73 20 65 61 63 68 20 72 6f 75 74 69 6e 65 |les each routine| 00000230 2c 22 0d 00 b4 4a f1 20 22 65 61 63 68 20 6f 66 |,"...J. "each of| 00000240 20 77 68 69 63 68 20 63 61 6c 63 75 6c 61 74 65 | which calculate| 00000250 73 20 52 30 20 3d 20 52 32 20 44 49 56 20 64 69 |s R0 = R2 DIV di| 00000260 76 69 73 6f 72 2c 20 52 31 20 3d 20 52 32 20 4d |visor, R1 = R2 M| 00000270 4f 44 20 64 69 76 69 73 6f 72 2e 22 0d 00 be 4f |OD divisor."...O| 00000280 f1 20 22 49 66 20 69 74 20 66 69 6e 64 73 20 61 |. "If it finds a| 00000290 6e 20 65 72 72 6f 72 20 69 74 20 70 72 69 6e 74 |n error it print| 000002a0 73 20 74 68 65 20 64 65 74 61 69 6c 73 20 61 6e |s the details an| 000002b0 64 20 77 61 69 74 73 20 66 6f 72 20 61 20 6b 65 |d waits for a ke| 000002c0 79 20 70 72 65 73 73 2e 22 27 27 0d 00 c8 04 0d |y press."''.....| 000002d0 00 d2 19 f4 20 4c 6f 61 64 20 67 65 6e 65 72 61 |.... Load genera| 000002e0 74 6f 72 20 63 6f 64 65 0d 00 dc 41 c8 99 20 22 |tor code...A.. "| 000002f0 4f 53 5f 46 69 6c 65 22 2c 20 20 20 35 2c 20 22 |OS_File", 5, "| 00000300 47 65 6e 65 72 61 74 6f 72 2e 47 65 6e 65 72 61 |Generator.Genera| 00000310 74 6f 72 22 20 b8 20 67 65 6e 74 79 70 25 2c 2c |tor" . gentyp%,,| 00000320 2c 2c 67 65 6e 6c 65 6e 25 0d 00 e6 35 e7 20 67 |,,genlen%...5. g| 00000330 65 6e 74 79 70 25 3c 3e 31 20 85 20 31 2c 20 22 |entyp%<>1 . 1, "| 00000340 47 65 6e 65 72 61 74 6f 72 20 63 6f 64 65 20 66 |Generator code f| 00000350 69 6c 65 20 6e 6f 74 20 66 6f 75 6e 64 22 0d 00 |ile not found"..| 00000360 f0 18 de 20 67 65 6e 65 72 61 74 6f 72 25 20 67 |... generator% g| 00000370 65 6e 6c 65 6e 25 0d 00 fa 3b c8 99 20 22 4f 53 |enlen%...;.. "OS| 00000380 5f 46 69 6c 65 22 2c 20 32 35 35 2c 20 22 47 65 |_File", 255, "Ge| 00000390 6e 65 72 61 74 6f 72 2e 47 65 6e 65 72 61 74 6f |nerator.Generato| 000003a0 72 22 2c 20 67 65 6e 65 72 61 74 6f 72 25 2c 20 |r", generator%, | 000003b0 30 0d 01 04 04 0d 01 0e 10 de 20 63 6f 64 65 25 |0......... code%| 000003c0 20 26 34 30 30 0d 01 18 17 72 30 3d 30 3a 72 31 | &400....r0=0:r1| 000003d0 3d 31 3a 72 32 3d 32 3a 72 33 3d 33 0d 01 22 04 |=1:r2=2:r3=3..".| 000003e0 0d 01 2c 0b 51 25 3d 31 30 30 30 0d 01 36 13 52 |..,.Q%=1000..6.R| 000003f0 25 3d 26 37 46 46 46 46 46 46 46 2d 51 25 0d 01 |%=&7FFFFFFF-Q%..| 00000400 40 13 53 25 3d 26 38 30 30 30 30 30 30 30 2b 51 |@.S%=&80000000+Q| 00000410 25 0d 01 4a 26 6d 61 78 63 25 3d 30 3a 20 6e 6d |%..J&maxc%=0: nm| 00000420 61 78 63 25 3d 30 3a 20 74 6f 74 63 25 3d 30 3a |axc%=0: totc%=0:| 00000430 20 63 6e 74 25 3d 30 0d 01 54 04 0d 01 5e 0c 5a | cnt%=0..T...^.Z| 00000440 62 61 73 65 25 3d 31 0d 01 68 12 5a 72 61 6e 67 |base%=1..h.Zrang| 00000450 65 25 3d 31 30 30 30 30 30 0d 01 72 04 0d 01 7c |e%=100000..r...|| 00000460 0d 5a 25 3d 5a 62 61 73 65 25 0d 01 86 05 f5 0d |.Z%=Zbase%......| 00000470 01 90 1b 20 20 f2 63 68 65 63 6b 28 20 5a 25 2c |... .check( Z%,| 00000480 2d 51 25 2c 51 25 2c 20 31 29 0d 01 9a 1b 20 20 |-Q%,Q%, 1).... | 00000490 f2 63 68 65 63 6b 28 2d 5a 25 2c 2d 51 25 2c 51 |.check(-Z%,-Q%,Q| 000004a0 25 2c 20 32 29 0d 01 a4 21 20 20 f2 63 68 65 63 |%, 2)...! .chec| 000004b0 6b 28 20 5a 25 2c 52 25 2c 26 37 46 46 46 46 46 |k( Z%,R%,&7FFFFF| 000004c0 46 46 2c 20 30 29 0d 01 ae 21 20 20 f2 63 68 65 |FF, 0)...! .che| 000004d0 63 6b 28 2d 5a 25 2c 52 25 2c 26 37 46 46 46 46 |ck(-Z%,R%,&7FFFF| 000004e0 46 46 46 2c 20 30 29 0d 01 b8 21 20 20 f2 63 68 |FFF, 0)...! .ch| 000004f0 65 63 6b 28 20 5a 25 2c 26 38 30 30 30 30 30 30 |eck( Z%,&8000000| 00000500 30 2c 53 25 2c 20 30 29 0d 01 c2 21 20 20 f2 63 |0,S%, 0)...! .c| 00000510 68 65 63 6b 28 2d 5a 25 2c 26 38 30 30 30 30 30 |heck(-Z%,&800000| 00000520 30 30 2c 53 25 2c 20 30 29 0d 01 cc 1f 20 20 f2 |00,S%, 0).... .| 00000530 63 68 65 63 6b 28 20 5a 25 2c 2d 51 25 2c 51 25 |check( Z%,-Q%,Q%| 00000540 2c 20 31 30 30 2b 30 29 0d 01 d6 1f 20 20 f2 63 |, 100+0).... .c| 00000550 68 65 63 6b 28 2d 5a 25 2c 2d 51 25 2c 51 25 2c |heck(-Z%,-Q%,Q%,| 00000560 20 31 30 30 2d 31 29 0d 01 e0 0f 20 20 63 6e 74 | 100-1).... cnt| 00000570 25 20 2b 3d 20 31 0d 01 ea 18 20 20 6c 25 20 3d |% += 1.... l% =| 00000580 28 61 66 74 25 2d 66 6f 72 65 25 29 2f 34 0d 01 |(aft%-fore%)/4..| 00000590 f4 11 20 20 74 6f 74 63 25 20 2b 3d 20 6c 25 0d |.. totc% += l%.| 000005a0 01 fe 12 20 20 e7 20 6c 25 3e 6d 61 78 63 25 20 |... . l%>maxc% | 000005b0 8c 0d 02 08 12 20 20 20 20 6d 61 78 63 25 20 3d |..... maxc% =| 000005c0 20 6c 25 0d 02 12 12 20 20 20 20 6e 6d 61 78 63 | l%.... nmaxc| 000005d0 25 3d 20 5a 25 0d 02 1c 07 20 20 cd 0d 02 26 52 |%= Z%.... ...&R| 000005e0 20 20 f1 22 43 75 72 72 65 6e 74 20 6d 61 78 20 | ."Current max | 000005f0 63 6f 64 65 20 6c 65 6e 67 74 68 20 22 3b 6d 61 |code length ";ma| 00000600 78 63 25 3b 22 20 69 6e 73 74 72 75 63 74 69 6f |xc%;" instructio| 00000610 6e 73 20 66 6f 72 20 64 69 76 69 73 6f 72 20 22 |ns for divisor "| 00000620 3b a4 6e 73 74 72 28 6e 6d 61 78 63 25 29 0d 02 |;.nstr(nmaxc%)..| 00000630 30 3a 20 20 f1 22 41 76 65 72 61 67 65 20 63 6f |0: ."Average co| 00000640 64 65 20 6c 65 6e 67 74 68 20 22 3b 74 6f 74 63 |de length ";totc| 00000650 25 2f 63 6e 74 25 3b 22 20 69 6e 73 74 72 75 63 |%/cnt%;" instruc| 00000660 74 69 6f 6e 73 22 27 27 0d 02 3a 09 5a 25 2b 3d |tions"''..:.Z%+=| 00000670 31 0d 02 44 17 fd 20 5a 25 3d 5a 62 61 73 65 25 |1..D.. Z%=Zbase%| 00000680 2b 5a 72 61 6e 67 65 25 0d 02 4e 13 85 20 31 2c |+Zrange%..N.. 1,| 00000690 20 22 41 6c 6c 20 64 6f 6e 65 22 0d 02 58 04 0d | "All done"..X..| 000006a0 02 62 05 e0 0d 02 6c 04 0d 02 76 27 dd f2 63 68 |.b....l...v'..ch| 000006b0 65 63 6b 28 4e 25 2c 53 54 41 52 54 25 2c 46 49 |eck(N%,START%,FI| 000006c0 4e 49 53 48 25 2c 20 72 65 70 6f 72 74 25 29 0d |NISH%, report%).| 000006d0 02 80 0e ea 20 6c 25 2c 20 72 6e 64 25 0d 02 8a |.... l%, rnd%...| 000006e0 30 f2 61 73 73 74 73 74 28 4e 25 29 3a f4 20 70 |0.asstst(N%):. p| 000006f0 72 6f 64 75 63 65 20 74 68 65 20 63 6f 64 65 20 |roduce the code | 00000700 74 68 65 6e 20 74 65 73 74 20 69 74 21 0d 02 94 |then test it!...| 00000710 04 0d 02 9e 2d e7 20 72 65 70 6f 72 74 25 3e 35 |....-. report%>5| 00000720 30 20 72 6e 64 25 3d b9 3a 72 65 70 6f 72 74 25 |0 rnd%=.:report%| 00000730 2d 3d 31 30 30 20 8b 20 72 6e 64 25 3d a3 0d 02 |-=100 . rnd%=...| 00000740 a8 24 e7 20 72 65 70 6f 72 74 25 20 3c 20 31 20 |.$. report% < 1 | 00000750 f1 20 3b 22 2c 20 22 3b a4 6e 73 74 72 28 4e 25 |. ;", ";.nstr(N%| 00000760 29 3b 0d 02 b2 13 e7 20 72 65 70 6f 72 74 25 20 |);..... report% | 00000770 3d 2d 31 20 f1 0d 02 bc 11 e7 20 72 65 70 6f 72 |=-1 ...... repor| 00000780 74 25 3d 31 20 8c 0d 02 c6 2c 20 20 f1 22 43 68 |t%=1 ...., ."Ch| 00000790 65 63 6b 69 6e 67 20 64 69 76 69 73 69 6f 6e 20 |ecking division | 000007a0 62 79 20 26 22 3b 7e 4e 25 3b 22 20 3d 20 22 3b |by &";~N%;" = ";| 000007b0 4e 25 0d 02 d0 18 20 20 6c 25 20 3d 28 61 66 74 |N%.... l% =(aft| 000007c0 25 2d 66 6f 72 65 25 29 2f 34 0d 02 da 30 20 20 |%-fore%)/4...0 | 000007d0 f1 22 55 73 69 6e 67 20 63 6f 64 65 2c 20 6c 65 |."Using code, le| 000007e0 6e 67 74 68 20 22 3b 6c 25 3b 22 20 69 6e 73 74 |ngth ";l%;" inst| 000007f0 72 75 63 74 69 6f 6e 73 3a 22 0d 02 e4 17 20 20 |ructions:".... | 00000800 f2 64 69 73 28 66 6f 72 65 25 2c 20 61 66 74 25 |.dis(fore%, aft%| 00000810 29 0d 02 ee 05 cd 0d 02 f8 31 e7 20 72 65 70 6f |)........1. repo| 00000820 72 74 25 3d 32 20 f1 22 46 75 72 74 68 65 72 20 |rt%=2 ."Further | 00000830 63 68 65 63 6b 73 20 66 6f 72 20 22 3b a4 6e 73 |checks for ";.ns| 00000840 74 72 28 4e 25 29 3b 0d 03 02 04 0d 03 0c 13 e7 |tr(N%);.........| 00000850 20 72 6e 64 25 20 41 25 3d b3 28 2d 31 29 0d 03 | rnd% A%=.(-1)..| 00000860 16 1d e3 20 46 25 3d 53 54 41 52 54 25 20 b8 20 |... F%=START% . | 00000870 46 49 4e 49 53 48 25 20 88 20 31 0d 03 20 0e 20 |FINISH% . 1.. . | 00000880 20 e7 20 72 6e 64 25 20 8c 0d 03 2a 46 20 20 20 | . rnd% ...*F | 00000890 20 e7 20 b3 28 32 29 3d 31 20 43 25 3d b3 28 26 | . .(2)=1 C%=.(&| 000008a0 37 46 46 46 46 46 46 46 29 2d 26 34 30 30 30 30 |7FFFFFFF)-&40000| 000008b0 30 30 30 20 8b 20 43 25 3d b3 28 26 30 30 30 37 |000 . C%=.(&0007| 000008c0 46 46 46 46 29 2d 26 30 30 30 34 30 30 30 30 0d |FFFF)-&00040000.| 000008d0 03 34 07 20 20 cc 0d 03 3e 0d 20 20 20 20 43 25 |.4. ...>. C%| 000008e0 3d 46 25 0d 03 48 07 20 20 cd 0d 03 52 18 20 20 |=F%..H. ...R. | 000008f0 41 25 3d ba 28 63 6f 64 65 25 29 3a 42 25 3d 21 |A%=.(code%):B%=!| 00000900 72 25 0d 03 5c 1b 20 20 44 25 3d 43 25 20 81 20 |r%..\. D%=C% . | 00000910 4e 25 3a 45 25 3d 43 25 20 83 20 4e 25 0d 03 66 |N%:E%=C% . N%..f| 00000920 1b 20 20 e7 20 28 41 25 3c 3e 44 25 29 84 28 42 |. . (A%<>D%).(B| 00000930 25 3c 3e 45 25 29 20 8c 0d 03 70 36 20 20 20 20 |%<>E%) ...p6 | 00000940 20 f1 22 45 72 72 6f 72 20 46 6f 75 6e 64 3a 20 | ."Error Found: | 00000950 22 3b 7e 43 25 3b 22 20 44 49 56 20 22 3b 7e 4e |";~C%;" DIV ";~N| 00000960 25 3b 22 3d 22 3b 7e 41 25 3b 22 20 22 3b 0d 03 |%;"=";~A%;" ";..| 00000970 7a 40 20 20 20 20 20 f1 3b 7e 43 25 3b 22 20 4d |z@ .;~C%;" M| 00000980 4f 44 20 22 3b 7e 4e 25 3b 22 3d 22 3b 7e 42 25 |OD ";~N%;"=";~B%| 00000990 3b 22 20 73 68 6f 75 6c 64 20 62 65 20 22 3b 7e |;" should be ";~| 000009a0 44 25 3b 22 20 61 6e 64 20 22 3b 7e 45 25 0d 03 |D%;" and ";~E%..| 000009b0 84 17 20 20 20 20 20 e7 20 73 70 6f 6f 6c 25 3d |.. . spool%=| 000009c0 a3 20 47 3d a5 0d 03 8e 07 20 20 cd 0d 03 98 05 |. G=..... .....| 000009d0 ed 0d 03 a2 05 e1 0d 03 ac 04 0d 03 b6 10 dd f2 |................| 000009e0 61 73 73 74 73 74 28 6e 25 29 0d 03 c0 27 72 30 |asstst(n%)...'r0| 000009f0 3d 30 3a 72 31 3d 31 3a 72 32 3d 32 3a 72 33 3d |=0:r1=1:r2=2:r3=| 00000a00 33 3a 72 34 3d 34 3a 72 35 3d 35 3a 6c 72 3d 31 |3:r4=4:r5=5:lr=1| 00000a10 34 0d 03 ca 04 0d 03 d4 49 f4 20 72 65 71 75 69 |4.......I. requi| 00000a20 72 65 20 77 6f 72 6b 52 65 67 20 69 66 20 6e 25 |re workReg if n%| 00000a30 20 63 61 6e 27 74 20 62 65 20 65 78 70 72 65 73 | can't be expres| 00000a40 73 65 64 20 61 73 20 61 20 76 61 6c 69 64 20 69 |sed as a valid i| 00000a50 6d 6d 65 64 69 61 74 65 20 63 6f 6e 73 74 0d 03 |mmediate const..| 00000a60 de 0c 77 6f 72 6b 52 3d 72 34 0d 03 e8 04 0d 03 |..workR=r4......| 00000a70 f2 10 73 69 67 6e 70 72 65 73 52 3d 72 33 0d 03 |..signpresR=r3..| 00000a80 fc 04 0d 04 06 15 e3 20 70 61 73 73 25 3d 30 20 |....... pass%=0 | 00000a90 b8 20 32 20 88 20 32 0d 04 10 0c 50 25 3d 63 6f |. 2 . 2....P%=co| 00000aa0 64 65 25 0d 04 1a 18 5b 20 20 20 20 20 20 20 20 |de%....[ | 00000ab0 20 20 4f 50 54 20 70 61 73 73 25 0d 04 24 3e 2e | OPT pass%..$>.| 00000ac0 66 6f 72 65 25 20 20 20 20 20 4f 50 54 20 a4 46 |fore% OPT .F| 00000ad0 61 73 74 44 69 76 28 72 30 2c 72 31 2c 72 32 2c |astDiv(r0,r1,r2,| 00000ae0 6e 25 2c 73 69 67 6e 70 72 65 73 52 2c 77 6f 72 |n%,signpresR,wor| 00000af0 6b 52 2c 70 61 73 73 25 29 0d 04 2e 18 2e 61 66 |kR,pass%).....af| 00000b00 74 25 20 20 20 20 20 20 53 54 52 20 72 31 2c 72 |t% STR r1,r| 00000b10 25 0d 04 38 18 20 20 20 20 20 20 20 20 20 20 20 |%..8. | 00000b20 4d 4f 56 20 70 63 2c 6c 72 0d 04 42 15 2e 72 25 |MOV pc,lr..B..r%| 00000b30 20 20 20 20 20 20 20 20 45 51 55 44 20 30 0d 04 | EQUD 0..| 00000b40 4c 05 5d 0d 04 56 05 ed 0d 04 60 05 e1 0d 04 6a |L.]..V....`....j| 00000b50 04 0d 04 74 43 dd 20 a4 46 61 73 74 44 69 76 28 |...tC. .FastDiv(| 00000b60 6f 75 74 71 25 2c 20 6f 75 74 72 25 2c 20 6e 75 |outq%, outr%, nu| 00000b70 6d 25 2c 20 63 6f 6e 73 74 25 2c 20 73 69 67 6e |m%, const%, sign| 00000b80 70 72 65 73 25 2c 20 77 6f 72 6b 25 2c 20 70 61 |pres%, work%, pa| 00000b90 73 73 25 29 0d 04 7e 0a ea 20 6c 65 6e 25 0d 04 |ss%)..~.. len%..| 00000ba0 88 11 41 25 20 20 20 3d 20 63 6f 6e 73 74 25 0d |..A% = const%.| 00000bb0 04 92 0d 42 25 20 20 20 3d 20 50 25 0d 04 9c 0f |...B% = P%....| 00000bc0 43 25 20 20 20 3d 20 6e 75 6d 25 0d 04 a6 10 44 |C% = num%....D| 00000bd0 25 20 20 20 3d 20 6f 75 74 71 25 0d 04 b0 10 45 |% = outq%....E| 00000be0 25 20 20 20 3d 20 6f 75 74 72 25 0d 04 ba 10 46 |% = outr%....F| 00000bf0 25 20 20 20 3d 20 77 6f 72 6b 25 0d 04 c4 14 47 |% = work%....G| 00000c00 25 20 20 20 3d 20 73 69 67 6e 70 72 65 73 25 0d |% = signpres%.| 00000c10 04 ce 17 6c 65 6e 25 20 3d 20 ba 20 67 65 6e 65 |...len% = . gene| 00000c20 72 61 74 6f 72 25 0d 04 d8 3c e7 20 6c 65 6e 25 |rator%...<. len%| 00000c30 3c 30 20 85 20 31 2c 20 22 47 65 6e 65 72 61 74 |<0 . 1, "Generat| 00000c40 6f 72 20 63 61 6c 6c 20 68 61 73 20 66 61 69 6c |or call has fail| 00000c50 65 64 2c 20 63 6f 64 65 20 22 2b c3 28 6c 65 6e |ed, code "+.(len| 00000c60 25 29 0d 04 e2 0f 50 25 20 20 2b 3d 20 6c 65 6e |%)....P% += len| 00000c70 25 0d 04 ec 10 20 20 20 20 20 3d 20 70 61 73 73 |%.... = pass| 00000c80 25 0d 04 f6 04 0d 05 00 12 dd 20 f2 64 69 73 28 |%......... .dis(| 00000c90 61 25 2c 20 62 25 29 0d 05 0a 14 ea 20 71 25 2c |a%, b%)..... q%,| 00000ca0 20 77 25 2c 20 71 24 2c 20 69 25 0d 05 14 16 e3 | w%, q$, i%.....| 00000cb0 20 71 25 3d 61 25 20 b8 20 62 25 2d 31 20 88 20 | q%=a% . b%-1 . | 00000cc0 34 0d 05 1e 20 20 c8 99 20 26 34 30 33 38 30 2c |4... .. &40380,| 00000cd0 20 21 71 25 2c 20 71 25 20 b8 20 2c 78 25 2c 79 | !q%, q% . ,x%,y| 00000ce0 25 0d 05 28 0a 20 71 24 3d 22 22 0d 05 32 16 20 |%..(. q$=""..2. | 00000cf0 e3 20 77 25 3d 78 25 20 b8 20 78 25 2b 79 25 2d |. w%=x% . x%+y%-| 00000d00 31 0d 05 3c 10 20 20 71 24 2b 3d bd 28 3f 77 25 |1..<. q$+=.(?w%| 00000d10 29 0d 05 46 06 20 ed 0d 05 50 13 20 69 25 20 3d |)..F. ...P. i% =| 00000d20 20 a7 71 24 2c 20 22 3b 22 29 0d 05 5a 0d 20 e7 | .q$, ";")..Z. .| 00000d30 20 69 25 3e 31 20 8c 0d 05 64 18 20 20 e3 20 77 | i%>1 ...d. . w| 00000d40 25 3d 69 25 2d 31 20 b8 20 31 20 88 20 2d 31 0d |%=i%-1 . 1 . -1.| 00000d50 05 6e 1d 20 20 20 e7 20 c1 71 24 2c 20 77 25 2c |.n. . .q$, w%,| 00000d60 20 31 29 20 3c 3e 20 22 20 22 20 8c 0d 05 78 15 | 1) <> " " ...x.| 00000d70 20 20 20 20 71 24 20 3d 20 c0 71 24 2c 20 77 25 | q$ = .q$, w%| 00000d80 29 0d 05 82 0c 20 20 20 20 77 25 3d 30 0d 05 8c |).... w%=0...| 00000d90 08 20 20 20 cd 0d 05 96 07 20 20 ed 0d 05 a0 06 |. ..... .....| 00000da0 20 cd 0d 05 aa 09 20 f1 20 71 24 0d 05 b4 05 ed | ..... . q$.....| 00000db0 0d 05 be 05 e1 0d 05 c8 04 0d 05 d2 0f dd 20 a4 |.............. .| 00000dc0 6e 73 74 72 28 6e 25 29 0d 05 dc 13 e7 20 94 28 |nstr(n%)..... .(| 00000dd0 6e 25 29 3c 36 35 35 33 36 20 8c 0d 05 e6 0c 20 |n%)<65536 ..... | 00000de0 3d 20 c3 28 6e 25 29 0d 05 f0 05 cc 0d 05 fa 11 |= .(n%).........| 00000df0 20 3d 20 22 26 22 2b c3 7e 28 6e 25 29 0d 06 04 | = "&"+.~(n%)...| 00000e00 05 cd 0d 06 0e 04 0d 06 18 0a dd 20 f2 65 72 72 |........... .err| 00000e10 0d 06 22 09 ee 20 85 20 87 0d 06 2c 1a f6 3a f1 |..".. . ...,..:.| 00000e20 22 20 77 69 74 68 20 63 6f 64 65 3a 20 22 3b 9e |" with code: ";.| 00000e30 2f 31 30 0d 06 36 0e e7 20 73 70 6f 6f 6c 25 20 |/10..6.. spool% | 00000e40 8c 0d 06 40 0b 20 2a 53 70 6f 6f 6c 0d 06 4a 0d |...@. *Spool..J.| 00000e50 20 73 70 6f 6f 6c 25 3d a3 0d 06 54 25 20 ff 28 | spool%=...T% .(| 00000e60 22 53 65 74 54 79 70 65 20 22 2b 73 70 6f 6f 6c |"SetType "+spool| 00000e70 70 61 74 68 24 2b 22 20 54 65 78 74 22 29 0d 06 |path$+" Text")..| 00000e80 5e 05 cd 0d 06 68 05 e1 0d ff |^....h....| 00000e8a