Marc de Groot wrote: > > brad....@symbios.com wrote: > > > > I have used Forth for bringup on new machines before, and have often > > wondered what is the minimum word set required to be implemented in > > assembly language. > > About seven years ago I remember seeing a list of Forth primitives that > was claimed to be a minimum set. If I remember correctly, there were > seven of them. > > Was it Mikael Patel who posted that list? My memory is dim. My name memory is dim, too. But I remember the words (and the implicit assumption that it's a threaded system with empty docol (everything is colon)): SP@ RP@ @ ! + (or 2*) NAND 0= EXIT Someone claimed that you can synthesize every logic operation out of NAND, but this is not true: you can't do left shifts (that's what + is for) and right shifts (that's what 0= is for). I thought, on the original list there was LIT, but look: : DUP SP@ @ ; : -1 ( x -- x 0 ) DUP DUP NAND DUP DUP NAND NAND ; : 1 -1 DUP + DUP NAND ; : 2 1 DUP + ; \ : 4 2 DUP + ; for 4 bytes/cell Forth : LIT RP@ @ 2 ( 4 ) + DUP RP@ ! @ ; And now we can do real stuff, since we can define variables. Their body consists of LIT
EXIT. Other important words: : AND NAND DUP NAND ; : BRANCH RP@ @ DUP @ + 2 + RP@ ! ; : ?BRANCH 0= RP@ @ @ AND RP@ @ + 2 + RP@ ! ; I think it would be really interesting do do this to a real end (e.g. the 30 eForth primitives), and try this. Should be dammed slow! BTW: RP! and SP! are done with looping, because you can either push or pop one element form these stacks per time. If you carefully save those parts you want to overwrite while processing, you can do it non-destructive (e.g. for a task switcher), as long as you don't overwrite the location that performs the RP! or SP! code ;-). -- Bernd Paysan "Late answers are wrong answers!" http://www.informatik.tu-muenchen.de/~paysan/