get primes working again

This commit is contained in:
~d6 2022-12-07 18:40:54 -05:00
parent 924fffe205
commit ae8af3c309
1 changed files with 15 additions and 20 deletions

View File

@ -26,20 +26,18 @@
( Smaller primes also run fairly quickly: 0x17b5d was ) ( Smaller primes also run fairly quickly: 0x17b5d was )
( determined to be prime in 0.02 seconds. ) ( determined to be prime in 0.02 seconds. )
%EMIT { #18 DEO } %SP { #2018 DEO }
%DIGIT { #00 SWP ;digits ADD2 LDA EMIT } %NL { #0a18 DEO }
%SPACE { #20 EMIT } %EXIT { #ff0f DEO BRK }
%NEWLINE { #0a EMIT } %DUP4 { OVR2 OVR2 }
%EMIT-BYTE { DUP #04 SFT DIGIT #0f AND DIGIT } %POP4 { POP2 POP2 }
%DEBUG { #ff #0e DEO }
|0100 |0100
( number to check comes first ) ( number to check comes first )
#fffe #0001 #ffff #fffb
OVR2 OVR2 ;is-prime32 JSR2 ( test for primality ) DUP4 ;is-prime32 JSR2 ( test for primality )
STH ;emit-long JSR2 SPACE STHr EMIT-BYTE NEWLINE ( output ) STH ;emit/long JSR2 SP STHr ;emit/byte JSR2 NL
#00 #00 DIV ( exit with /0 to make timing easier ) EXIT
BRK
( include 32-bit math library ) ( include 32-bit math library )
~math32.tal ~math32.tal
@ -75,12 +73,9 @@
&i-divides-x POP4 POP4 #00 JMP2r ( since i divides x, not prime ) &i-divides-x POP4 POP4 #00 JMP2r ( since i divides x, not prime )
&finished POP4 POP4 #01 JMP2r ( didn't find divisors, prime ) &finished POP4 POP4 #01 JMP2r ( didn't find divisors, prime )
( print a long value as hex ) @emit
@emit-long ( x** -> ) &long SWP2 ,&short JSR
SWP2 SWP EMIT-BYTE EMIT-BYTE &short SWP ,&byte JSR
SWP EMIT-BYTE EMIT-BYTE JMP2r &byte DUP #04 SFT ,&char JSR
&char #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
( convenience for less branching when printing hex ) JMP2r
@digits
30 31 32 33 34 35 36 37
38 39 61 62 63 64 65 66