Re: Build your own Forth for Microchip PIC (Episode 837)
- From: Gerry <gerry@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 25 Jun 2007 00:39:44 -0700
You should look into CMForth that was used on the NC4000. It had a
relatively simple cross compiler that is relatively easy to convert to
another platform. It is a little confusing at first because many low
level words exist as machine level words and are only binary codes.
That means that it isn't necessarily minimal. Maybe I should stop
complaining because I have my own bytecode interpreter that has about 35
instructions. I factored the binary ops by writing a common routine that
pops the stack into a temp register (binopsetup). So most of those
instructions were little more than doing a binopsetup followed by the
actual task of the instruction, then writing back the result to the new
TOS. That accounted for about half the group
(+,-,=,!=,>,<,>=,<=,&,|,^,&&,||,<<,>>)
An interesting question is how many of these could you actually factor?
All 6 comparison operators are buildable from a subtract, as is addition
if you throw in ^. AND an OR are negative complements of one another so
you really only need NAND to build both (and ^ too IIRC). && and || are
buildable from comparison and logical ops. Left shift can be done via
recursive addition. Not sure about right shift.
So the kernel for the 15 above tentatively is: -, NAND, >>
You then throw in the equivalents for ! and @, unary ops, pushing
numbers on the stack, conditional and unconditional goto, and you're
pushing 20. Since I was targeting a traditional language I didn't throw
in but a couple of stack manipulation operators. I guess implementing
DROP, SWAP, DUP, OVER would be good. Any others?
I'm a bit surprised that nobody has mentioned Buzzard to you (unless I
missed it). See
http://www.ioccc.org/1992/buzzard.2.design
which develops a small Forth system from 15 primitives.
Gerry
.
- Follow-Ups:
- References:
- Prev by Date: Re: M/MOD
- Next by Date: Re: M/MOD
- Previous by thread: Re: Build your own Forth for Microchip PIC (Episode 837)
- Next by thread: Re: Build your own Forth for Microchip PIC (Episode 837)
- Index(es):