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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5. THE GILBREATHS’ <strong>FORTH</strong> PROGRAM FOR THE SIEVE ALGORITHM<br />

The <strong>FORTH</strong> version <strong>of</strong> <strong>the</strong> Gilbreaths’ benchmark, as presented in <strong>the</strong>ir BYTE articles, is<br />

shown below:<br />

1.<br />

2.<br />

3,<br />

4.<br />

5.<br />

6.<br />

7.<br />

8.<br />

9.<br />

10.<br />

14”<br />

12.<br />

13.<br />

ai90 CONSTAMT SIZE<br />

0 VARIABLE FLAGS SlZE ALLOT<br />

: OO-PRIHE<br />

FLAGS SIZE 1 FILL<br />

0 SIZE 0<br />

DO FLAGS I + C8<br />

IF I DUP + 3 + DUP I +<br />

THEN<br />

BEGIN DUP SIZE <<br />

UHILE 0 OVER FLAGS + C! OVER + REPEAT<br />

DROP DROP I+<br />

LOOP<br />

. .I‘ PRIMES“ ;<br />

The Gilbreaths admit <strong>the</strong>y are not skilled <strong>FORTH</strong> programmers; un<strong>for</strong>tunately, <strong>the</strong>ir<br />

<strong>FORTH</strong> program reflects <strong>the</strong>ir lack <strong>of</strong> skill. There are two errors in <strong>the</strong> programs that<br />

must be corrected to obtain correct res~lts.~ First, <strong>the</strong> condition <strong>for</strong> testing <strong>the</strong><br />

completion <strong>of</strong> <strong>the</strong> BEGIN ... WHILE ... REPEAT (lines 8 and 9) loop is erroneously written as<br />

BEGIN DUP SIZE

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

Saved successfully!

Ooh no, something went wrong!