2022-09-23 12:56:06 +00:00
|
|
|
|
|
|
|
; The "Byte Sieve" test. https://en.wikipedia.org/wiki/Byte_Sieve
|
|
|
|
|
2024-12-06 21:00:51 +00:00
|
|
|
%import textio
|
|
|
|
%zeropage basicsafe
|
|
|
|
%option no_sysinit
|
|
|
|
|
2022-09-23 12:56:06 +00:00
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
|
|
|
|
uword count
|
|
|
|
uword i
|
|
|
|
uword prime
|
|
|
|
uword k
|
|
|
|
const uword SIZEPL = 8191
|
|
|
|
uword @zp flags_ptr = memory("flags", SIZEPL, $100)
|
|
|
|
|
|
|
|
txt.print("calculating...\n")
|
|
|
|
|
2022-09-27 20:36:10 +00:00
|
|
|
sys.memset(flags_ptr, SIZEPL, 1)
|
|
|
|
count = 0
|
|
|
|
for i in 0 to SIZEPL-1 {
|
2024-02-04 22:18:11 +00:00
|
|
|
if flags_ptr[i]!=0 {
|
2022-09-27 20:36:10 +00:00
|
|
|
prime = i + i + 3
|
|
|
|
k = i + prime
|
|
|
|
while k <= SIZEPL-1 {
|
2024-02-04 22:18:11 +00:00
|
|
|
flags_ptr[k] = 0 ; false
|
2022-09-27 20:36:10 +00:00
|
|
|
k += prime
|
2022-09-23 12:56:06 +00:00
|
|
|
}
|
2024-12-06 21:00:51 +00:00
|
|
|
; txt.print_uw(prime)
|
|
|
|
; txt.nl()
|
2022-09-27 20:36:10 +00:00
|
|
|
count++
|
2022-09-23 12:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-24 11:54:00 +00:00
|
|
|
txt.nl()
|
2022-09-23 12:56:06 +00:00
|
|
|
txt.print_uw(count)
|
|
|
|
txt.print(" primes\n")
|
|
|
|
}
|
|
|
|
}
|