In Forth Threading (Is Not Process Threads), I commented on the fig Forth models insisting on using the CPU stack register for parameters. The code I presented for the 6800 follows that design choice, but the code I presented there for the 6809 and 68000 does not. Here I'll show, for your consideration, the snippets for indirect threading on the 6800 done right (according to me) -- with the CPU stack implementing RP and the synthesized stack implementing Forth's SP.
You'll note that the code here will end up maybe 5% slower and 5% bigger overall than the code that the fig model for the 6800 shows. But it will not mix return addresses and parameters on the same stack, and it should end up a bit easier to read and analyze, meaning that it should be more amenable to optimization techniques, when generating machine code instead of i-code lists.
In the code below, the virtual registers are allocated as follows:
- W RMB 2 the instruction register points to 6800 code
- IP RMB 2 the instruction pointer points to pointer to 6800 code
- * RP is S
- FSP RMB 2 Forth SP, the parameter stack pointer
- UP RMB 2 the pointer to base of current user's 'USER' table ( altered during multi-tasking )
- N RMB 10 used as scratch by various routines
The symbol table entry remains the same:
HEADERSo we won't discuss it here. (See the discussion in the post on threading techniques.)
LABEL CODE_POINTER
DEFINITION
I won't repeat the fig model here. I'll be bringing more of it into the discussion than I did in the post on threading techniques, refer to the model in my repository, here: https://sourceforge.net/p/asm68c/code/ci/master/tree/fig-forth/fig-forth.68c.
This is an exercise in refraining from early optimization, so the parameter stack pointer will point to the last item pushed, even though it's tempting to cater to the lack of negative index offset in the 6800 and point to the first free cell beyond top of stack.
The inner interpreter of the virtual machine looks the same, but the code surrounding it changes.
PULABX is only used by "!" (STORE), so let's start the rework there: