Playing With Electricity

Author(s): Harvey Taylor
Publication: ZX-Appeal
Date: January 1986
Pages: 6-7

Well I finally got my printer . You will just have to put up with my messing around with different typestyles. Between Quill and the LX80, there are a lot of different combinations to try.

In the last column I managed to get to Paul before the deadline (sigh), I posted some results ofthe Sieve of Eratosthenes in Superbasic and 68008 Assembler. Now that I have my printer, I can get the code on paper & so here it is. Any of you who may be experienced 68K hackers may see ways to optimize the code. The ‘GET FLP2_standard_hdr3’ line at the beginning is an instruction to the assembler to get the file which contains all the QDOS system calls & values. ( Well most anyway, I’m adding them as I use them & there are 150+ QDOS calls documented.)

By the way, that reminds me. Anybody who is going to get into some serious programming will find ADRIAN DICKENS “QL ADVANCED USERS QUIDE” invaluable . There is also available from Boston Sinclair, The QL Technical Guide , (US$20.00 + shipping) which has some additional information.

Also by the way, If this article should happen to fall into the hands of any other QL owner, drop me a line. I’m trying to maintain contact with as many QL’ers as possible.

Back to the listing, as you see, most of the nonessential code consists of system calls (via QDOS,QDOS_N,VECTOR,&VECTOR N). This makes it easy to do the simple sorts of housekeeping things that always need to be taken care of ……BUT, IT MEANS YOU GOTTA DO IT THEIR WAY. WHICH IS OKAY IF ‘THEY’ HAPPEN TO BE GOING YOUR WAY, (EXCEPT HOW OFTEN DOES THAT HAPPEN?)

THERE is a direct correlation between the assembler listings and the basic code of last time which will give you an idea what the code is about, label by label. GET IN TOUCH WITH ME IF YOU HAVE QUESTIONS.

*                 SIEVE OF ERASTOSTHENES
* IN ASSSEMBLER
* SEPT 27/85
*
GET 'flp2_STANDARD_HDR3'
SIZE EQU 8192
ITER EQU 100
*
START LEA SCR_PAR,A1 * point A1 to screen parameters
VECTOR UT_SCR,A2 * macro
BNE ERROR
LEA SCR_CHAN(PC),A1
MOVE.L A0,(A1) * Save the screen channel #

MOVE.L A0,A4 * A4 = SCR_CHAN
MOVEQ #0,D1
QDOS_N MT_SCLCK,1 * set clock to 0
BSR RD_TIME * using the qdos macro
MOVE.L #SIZE,D1 * '_N' indicates no error testing

MOVEQ #-1,D2
QDOS MT_ALCHP,1 * allocate space on common heap
BNE ERROR
MOVE.L A0,A5 * A5 = BASE ADDR
MOVE.L #ITER,D5 * D5 = # OF ITERATIONS

I_LOOP MOVE.L A5,A0 * A0 = BASE ADDR
MOVE.L #SIZE,D3
MOVE.B #01,D1
ARRAY MOVE.B D1,(A0)+ * initialize array to 1's
DBRA D3,ARRAY
MOVE.L #0,D0 * D0=INDEX
MOVEQ #0,D1 * D1=K, ANOTHER INDEX
MOVEQ #0,D2 * D2=COUNT
MOVEQ #0,D3 * D3=PRIME
F_LOOP TST.B 0(A5,D0)
BEQ NEXTI
MOVE.L D0,D3
ADD.L D3,D3
ADDQ.1 #3,D3 * PRIME=i+i+3
MOVE.L D3,D1
ADD.L D0,D1 * K=i + PRIME : D1=D0 + D3
WHILE CMPI.L #SIZE,D1
BHI INCOUNT
CLR.B 0(A5,D1)
ADD.L D3,D1
BRA WHILE
INCOUNT ADDQ #1,D2 * COUNT +1

NEXTI ADDQ #1,D0 * INDEX +1
CMPI.L #SIZE,D0
BLS F_LOOP
DBRA D5,I_LOOP
MOVE.L D2,-(A7)
BSR SND_MSG2
MOVE.L (A7)+,D1
MOVE.L A4,A0 * CHAN ID
VECTOR UT_MINT,A2 * print the integer in D1.W
BNE ERROR
BSR NEWLINE
BSR RD_TIME
BRA EXIT

ERROR VECTOR UT_ERR0,A2 * PRINT QDOS ERROR MSG TO CONSOLE
*
EXIT LEA SCR_CHAN(PC),A1
MOVE.L (A1),A0
QDOS_N IO_CLOSE,2
MOVEQ #0,D0 * RETURN TO BASIC WITH NO ERROR FLAG
RTS

RD_TIME QDOS_N MT_RCLCK,1
LEA BUF_TOP(PC),A1
SUBA.L A6,A6 * zero A6 for CN_DATE
VECT_N CN_DATE,A2
MOVE.W (A1)+,D2
MOVEQ #-1,D3
LEA SCR_CHAN(PC),A0
MOVE.L (A0),A0
QDOS IO_SSTRG,3
BNE ERROR
NEWLINE MOVEQ #-1,D3
QDOS SD_NL,3
RTS
SND_MSG2 LEA MSG2(PC),A1
SENDIT LEA SCR_CHAN(PC),A0 * RETRIEVE CHANNEL #
MOVE.L (A0),A0
VECTOR UT_MTEXT,A2
RTS
*
MSG2 DC.W M2END-M2
M2 DC.B ' COUNT= '
M2END
*
MSG1 DC.W M1END-M1
M1 DC.B 'SIEVE OF ERATOSTHENES',10
M1END

SCR_CHAN DS.L 1
SCR_PAR DC.W $0401
DC.W $0004
DC.W 384
DC.W 128
DC.W 64
DC.W 32

BUFFER DS.L 30
BUF_TOP
ADDR DC.W 08
CON_BUFR DS.L 2
STACK DS.L 4
STK_TOP
END

Also printed in ZX-Appeal December 1985.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.