
 1000  *SAVE SIEVE OF ERATOSTHENES.1
 1010  *--------------------------------
 1020  *   CODED BY PETER J. MCINERNEY, NEW ZEALAND
 1030  *--------------------------------
 1040         .OR $3800
 1050  ARRAY  .EQ $4000
 1060  *--------------------------------
 1070  SIEVE  MOVE    #999,D6   DO 1000 TIMES
 1080  *---CLEAR WORKING ARRAY----------
 1090  .1     MOVE    #ARRAY,A0 CLEAR ARRAY FROM
 1100         MOVE    #$FFF,D0  $4000 TO $7FFF
 1110  .2     CLR.L   (A0)+
 1120         DBF     D0,.2
 1130  *---INIT VARIABLES---------------
 1140         MOVEQ   #3,D0     START AT 3
 1150         MOVEQ   #1,D1     SUM OF ODD NUMBERS
 1160         MOVEQ   #1,D2     COUNT OF ODD NUMBERS
 1170         MOVEQ   #1,D3     USED FOR STRIKING NON-PRIMES
 1180         MOVE    #ARRAY,A0 START OF ARRAY
 1190         BRA.S   .4        JUMP INTO LOOP
 1200  *---START SIFTING----------------
 1210  .3     ADDQ    #1,D2     COUNT ODD NUMBERS
 1220         ADD     D2,D1     GET SUM OF ODDS
 1230  .4     CMPI.B  #0,0(A0,D0) IS THIS A PRIME?
 1240         BNE.S   .6          NO
 1250  *---STRIKE OUT MULTIPLES---------
 1260         MOVE    D1,D4     GET 8*S+1 = N*N
 1270         ASL     #3,D4
 1280         ADDQ    #1,D4
 1290         MOVE    D0,D5     ONLY STRIKE ODD MULTIPLES
 1300         ASL     #1,D5
 1310  .5     MOVE.B  D3,0(A0,D4)  STRIKE ONE
 1320         ADD     D5,D4        NEXT STRIKE
 1330         CMPI    #$4000,D4    ...FINISHED?
 1340         BLS     .5           ...NO
 1350  *---GET NEXT SIEVE SIZE----------
 1360  .6     ADDQ    #2,D0     NEXT ODD NUMBER
 1370         CMPI    #127,D0   UNTIL SQRT $4000-1
 1380         BLS     .3
 1390  *---DO IT ALL 1000 TIMES---------
 1400         DBF     D6,.1   NEXT TIME
 1410         RTS

