Hi Wis,

I've got some time to work on the docs. The webpage got
a small update as well. To answer your questions (Michael
did answer most of them, but he seemed to be unsure
himself ;) I'll try to do it myself.

First you may want to read the
http://www.bradrodriguez.com/papers/moving1.htm page and there the
section about the ITC technique.
Esp the picture tells almost everything.

Most of the inner interpreter code is in the file
core/amforth-interpreter.asm.

The Forth VM (inner interpreter) consists of a few registers, that
do all the work: W, IP, X and stack pointers for
data and return stacks. These names are not related to similiar
named atmega registers!

> (p. 9)        EXECUTE
> 
> Q: When is EXECUTE, um, executed? I'm not clear on what this is used
> for.

Execute has two aspects: One is part of the inner interpreter (starting
at the DO_EXECUTE label until the ijmp instruction) and the other one
is the forth word EXECUTE (in words/execute.asm). The latter simply
fetches the Top-Of-Stack element into the W register and calls the
former.

The inner interpreter execute reads the content of the address,
the W register points to. That number is itself an address, this
time of real machine code and the final JMP [X] branches to that
code. It is expected that this code sooner or later jumps back
to the inner interpreter (to DO_NEXT) _and_ keeping the W and IP
registers intact.

> (p. 9)        NEXT [ . . . ] This last step finally jumps to the machine
> code pointed to by the X scratch pad register.

NEXT _is_ the inner interpreter (label DO_NEXT in
amforth-interpreter.asm). It reads the flash cell, IP points to,
stores that number in W and increases IP by 1 (for the next round).
Finally the above execute is done.

In addition to the generic ITC model, the amforth inner interpreter
checks for machine interrupts and handles tham if any occured. This
is another story, however.

> 
> Q: To be clear, the machine code jumps to NEXT when it has completed.
> Correct?

Yes. See above. Every assembly word in the words/ directory has
the phrase jmp_ DO_NEXT at least once. There is no RET instruction
to get back (jmp_ is a macro to optimize between jmp and rjmp,
another story).

> 
> (p. 9)        EXIT The code for EXIT (aka UNNEST) is the forth word EXIT in
> the dictionary. It reads the IP from the return stack and jumps to
> NEXT. The return stack pointer is incremented by 2 (1 flash cell).
> 
> Q: I think EXIT pops the top of the return stack into the IP.  That
> way, the second step of NEXT gets the correct value. Correct?

Yes. See code in words/exit.asm.

> 
> (p. 9)        DO_DOES This code is the runtime part of the forth word DOES>
> . It pushes the current address of the MCU IP register onto the
> returnstack and jumps to DO_DOES. DO_DOES gets that address back,
> saves the current IP and sets the forth IP to the address it got from
> the stack. Finally it continues with NEXT.
> 
> Q.  Is this effectively a subroutine call?

DOES> is a rather difficult topic. It is easy to use, but
hard to explain and the implementation in amforth is not
the most obvious one. DOES> itself is not really
a subroutine call its more like a partial redefinition of a
colon word, which is a subroutine call. In the docs I've just removed
the section for now (it was simply garbage after all). I'll rewrite it
from scratch. Expect one page text per assembly code line ;)

I think for the beginning you can savely ignore both does> and
interrupts.

HTH
Matthias

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to