mirror of
https://github.com/bobbimanners/EightBall.git
synced 2024-10-19 23:23:49 +00:00
cdbfeafda9
This fixes a memory corruption bug that occurred when compiling code with subroutines. The symbol table was corrupting the source code. This was showing up on 6502 systems only (seemed okay on Linux).
48 lines
657 B
Plaintext
48 lines
657 B
Plaintext
' Sieve of Eratosthenes
|
|
|
|
byte A[400] = 1
|
|
call doall(20)
|
|
end
|
|
|
|
sub doall(word nr)
|
|
word n = nr * nr
|
|
pr.msg "Sieve of Eratosthenes ..."
|
|
pr.msg "nr is "; pr.dec nr; pr.nl
|
|
call sieve(n, nr)
|
|
call printresults(n)
|
|
return 0
|
|
endsub
|
|
|
|
sub sieve(word n, word nr)
|
|
pr.msg "Sieve"
|
|
word i = 0; word j = 0
|
|
for i = 2 : (nr - 1)
|
|
if A[i]
|
|
j = i * i
|
|
while (j < n)
|
|
A[j] = 0
|
|
j = j + i
|
|
endwhile
|
|
endif
|
|
endfor
|
|
return 0
|
|
endsub
|
|
|
|
sub printresults(word n)
|
|
word i = 0
|
|
for i = 2 : (n - 1)
|
|
if A[i]
|
|
if i > 2
|
|
pr.msg ", "
|
|
endif
|
|
pr.dec i
|
|
endif
|
|
endfor
|
|
pr.msg "."
|
|
pr.nl
|
|
return 0
|
|
endsub
|
|
|
|
|
|
|