Matthias, Thank you for taking time to respond. It is an unexpected pleasure. Between you and Michael, I think I understand the inner interpreter well now - I've been looking at the technical document intermittently for a while.
I've been doing hardware and I'm finishing an ATXMEGAxx4U board so I'm getting back into the software. Since I'll need a couple of assembly language Forth words for external I/O, I'm looking into the Forth guts to see how to do it. For background, I'll be looking harder at the DOES> word - I'm glad to see that it isn't the easiest to learn. I've been studying it; perhaps now it will click with the info you and Michael shared. BTW: the link to the "Mailing List Archive" in the FAQ (http://amforth.sourceforge.net/faq.html) Gives "ERROR Forum not found". Also, is the mailing list closed? I don't see how to join it. Regards, -wis -----Original Message----- From: Matthias Trute [mailto:mtr...@web.de] Sent: Wednesday, February 06, 2013 11:46 AM To: Everything around amforth Subject: Re: [Amforth] inner interpreter operation. 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 ------------------------------------------------------------------------------ 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