Quote:
Garth, I know that your version of Forth uses absolute addressing for BRANCH
I don't remember having said that, but yes it is true of my '816 Forth. If/when I ever get my '02 Forth cleaned up for publication, I'm going to have to change a few things that are left that a particular company could claim a copyright on it, and at the same time I want to get rid of that need to add the relative address to the current address to get the target address.
Quote:
but let's assume that you EXECUTE a fig-Forth style relative branch instruction. Is the target of the branch relative to the IP of the EXECUTE instruction, or relative to the address of the BRANCH instruction? Also, does the relative address literal come directly after the EXECUTE, or directly after the BRANCH?
EXECUTE is never relative in 6502 Forth to my knowledge like branch and zbranch sometimes are. (branch and zbranch are internals compiled by things like IF and ELSE.) The absolute address for EXECUTE to execute comes off the top of the data stack. There's never a need to have it immediate, because any word (and I don't mean 16-bit entity, but rather that every type of routine in Forth is called a "word") that you write automatically becomes part of the language, so you just put its name in the source code where you want it executed, for example "FOOBAR" and not "EXECUTE FOOBAR". You could do something like
Code:
['] FOOBAR EXECUTE
which would take the code field address of FOOBAR and compile it as a literal to put on the stack at execution time and do the same thing, but it would be rather pointless and inefficient. But if you want to do something like calculate the offset into a table of word addresses depending on conditions at execution time, you'll end up with the result on the dtat stack and then do @ EXECUTE (or PERFORM). My '816 Forth EXECUTE is:
Code:
HEADER "EXECUTE", NOT_IMMEDIATE ; ( addr -- )
EXECUTE: PRIMITIVE
LDA 0,X ; Get the address from the top of the data stack
STA W ; and put it in the word pointer.
INX_INX ; Drop the top stack item since we're done with it.
JMP W-1
;-------------------
We get off topic a lot but I guess it applies to the OP.