>Prime_MC * Copyright *** Jason Wolfe 1993 *** M A program which uses machine code to calculate a list of prime numbers (Z It is fast. I personally can't think of any way to increase the speed any further. 2S I have left the code disassembled for those who may be interested in how the < program works. F 26,12 P t~@ Z A%(20000) d@%=8:A%(1)=3:count%=2:=0 n N%= 5 10000 2 xsqr%=(N%):loop%=1 ; A%(loop%) > sqr% A%(count%)=N%:N%;:count%+=1:t`@ N% A%(loop%) = 0 t`@ loop%+=1:tB@  '/100  ! Machine Code Prime Numbers.  @%=8 assemble call    call !sr=(!nm)  code " TNA , 6 @assemble Ja=0 Tb=1 ^c=2 hd=3 r num=4 | count=5  base=6  loop=7  sqr=8  test=9   sr 32  nm 32  cnt 32  code 1000   vdu=256 bse=&10000  !bse=3  !cnt=1  !nm=5  & pass= 0 3 3 0 P%=code :[ D OPT pass N X .string bEQUS " " l ALIGN v MOV loop,#0 LDR count,cnt LDR num,nm LDR sqr,sr   .test1 MOV base,#bse ADD base,base,loop,LSL#2 LDR test,[base] CMP test,sqr  BLE test2 CMP num,#&50000 BGT printN MOV base,#bse  ADD base,base,count,LSL#2 STR num,[base]  ADD count,count,#1 *STR count,cnt 4 .printN >MOV R0,num HADR R1,string RMOV R2,#16 \SWI "OS_ConvertCardinal4" fSWI "OS_PrettyPrint" pSWI vdu+32 z BAL out   .test2  MOV a,num  MOV b,#0  MOV c,#0 MOV d,#1<<31   .mod_loop MOVS a,a,ASL#1  ADC b,b,b CMP b,test SUBGE b,b,test RGE c,c,d MOVS d,d,LSR#1 BNE mod_loop  $.mod_finish . CMP b,#0 8 BEQ out B L .inc_loop VADD loop,loop,#1 ` BAL test1 j t.out ~ADD num,num,#2 STR num,nm MOV PC,R14 ]  ' A$=