From ae8af3c309341624d618da34ca8ddebd0b70df26 Mon Sep 17 00:00:00 2001 From: d6 Date: Wed, 7 Dec 2022 18:40:54 -0500 Subject: [PATCH] get primes working again --- primes32.tal | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/primes32.tal b/primes32.tal index 57b5dbf..3f1e1bb 100644 --- a/primes32.tal +++ b/primes32.tal @@ -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