User Tools

Site Tools


en:words:kernel_embedded:minimum_word_set

Minimal Word Set

How many primitives does a Forth need to get it started?

Surprisingly few, as you can see with Gforth EC, which provides a high-level definition for almost every primitive. But beware! If you omit too much, you risk circular behaviour (loops).

We need in any case:

:dodoes as generalized entry point for all high-level definitions, or

Call for primitive-centric implementations.

@ and ! to access the memory.

>R and R> for the return stack, so anything can be moved.

+ or 2* for Artihmetik.

And NAND as a universal bit instruction.

?BRANCH or 0= for branches.

And finally ;S and

EXECUTE for execution.

Everything else can be defined from these words, even if it then needs temporary variables:

: lit' r> @ ;
: cell lit' [ 2 , ] ; \ oder 4 oder 8 ...
: tmp1 lit' [ here cell+ , 0 , ] ;
: dup tmp1 ! tmp1 @ tmp1 @ ;
: lit r> dup cell + >r @ ;

By Bernd Paysan, Translation Juergen Pintaske 20151121

en/words/kernel_embedded/minimum_word_set.txt · Last modified: 2022-12-02 15:48 by juergenuk