26.10.2013 Views

Sieve of Eratosthenes benchmarks for the Z8 FORTH microcontroller

Sieve of Eratosthenes benchmarks for the Z8 FORTH microcontroller

Sieve of Eratosthenes benchmarks for the Z8 FORTH microcontroller

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>the</strong> limit to eliminate many multiples is shown below. The additional <strong>FORTH</strong> words used<br />

in this benchmark (limit>i:if and word-<strong>the</strong>n) are defined in Appendix @:<br />

1. 8190 CONSTANT SIZE<br />

2. SIZE 1+ ARRAY-VARIABLE FLAGS<br />

3. : SIEVESUB<br />

4. FLAGS<br />

5. I I DUQ+3+<br />

6.. SIZE 0<br />

7. FILL-ROW ;<br />

a. 1 I FLAGS + C! ;<br />

9. : OUTER-LOOP<br />

10. do-code,<br />

11. LTBAI,<br />

12. nx if,<br />

13. limit>i:if,<br />

14. GO<strong>FORTH</strong> SIEVESUB<br />

15. word-<strong>the</strong>n,<br />

16. inc-prime-count,<br />

17. <strong>the</strong>n,<br />

18. 1 oop- code I<br />

19. EXIT, ;<br />

20. : DO-PRIME<br />

21. FLAGS SIZE 1+ 1 FILL<br />

22. 0<br />

23. SIZE 0 OUTER-LOOP<br />

24. . -I1 PRIMES" ;<br />

Define constant SlZE with value 8190<br />

Define an array <strong>of</strong> length 8191 (0 .. 8190)<br />

Define a <strong>FORTH</strong> yosd to mark primes<br />

Put <strong>the</strong> address <strong>of</strong> FLAGS on <strong>the</strong> stack<br />

Put row index and PRIME (2*I+3) on stack<br />

Matrix size, initialization constant to stack<br />

Invoke word to zero last row <strong>of</strong> matrix<br />

Restore <strong>the</strong> value <strong>of</strong> <strong>the</strong> primts FLAG<br />

Push <strong>the</strong> Limit, starting index to RStack<br />

Load <strong>the</strong> byte at I, test if on-zero<br />

If <strong>the</strong> byte at 1 is nonzero; mrk its wttiptes<br />

Test if LIMIT > outer-loop index<br />

Use a <strong>FORTH</strong> word to mark ntultiples<br />

Pairs with limit>i:if conditional test<br />

Increment prim count<br />

End <strong>of</strong> multiple-marking section<br />

End <strong>of</strong> outer Loop<br />

Exit back to DO-PRIME word<br />

Define a <strong>FORTH</strong> word called DO-PRIME<br />

Initialize 8191 bytes <strong>of</strong> FLAGS to 1<br />

Initialize prim count to 0<br />

Loop to examine 8191 FLAG bytes<br />

Print out prime countl.<br />

18

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!