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