The figForth Virtual Machine Explained

  Some parts of this page/site are currently incomplete & will be updated asap
  Other parts will change continually so use “Refresh” in your browser !!
  There is extensive use of “Tooltips” text to support learning which do not seem to render on a Smartphone. This site is best viewed via a computer’s HD monitor


Previous Page: Virtual Machines Explained

The figForth Virtual Machine

A number of high-level languages have employed a VM internally to avoid platform dependence and to isolate programs from hardware details

Image#1: Languages that use Virtual Machines   (Taivalsaari 2003, p. 13)

Image#2: Forth is an “interesting” VM…   (Taivalsaari 2003, p. 30)

As Taivalsaari points out above, the Forth VM is very simple; 1

How does the figForth Virtual Machine (“VM”) work?

(Taivalsaari 2003, p. 30) says: “The VM consists of a small number of distinct components (stacks, dictionary, interpreter, virtual registers, primitives)”

Talking About Hardware for a Moment…

This is about figForth being hosted on an embedded system as illustrated in the image below

Image#3: A proposed “New Model” Embedded Forth System - (Husband 2020)

Here we talk about a particular aspect of how a real system is designed or arranged to as to host a viable figForth Virtual Machine and everything associated with that VM 2

A detailed discussion of the New figForth Hardware Model

The figForth Virtual Machine Registers

When you have chosen which platform to use, and being aware of the Instruction Set of the CPU being used in your platform, you can then attend to the figForth VM…

If you have decided upon an embryonic figForth model for your platform, this should all have been done…

A virtual machine must have virtual machine registers to hold the data that it works with and they must be “mapped” to the CPU’s “real” registers. figForth’s 8080/Z80 model are shown below 4

Image#4: figForth VM Registers mapped to Zilog eZ80 Registers 4
(Husband 2011), based upon (Ting 2013, p. 27)

“The data (parameter) stack pointer (“SP”) and the return stack pointer (“RP”) point to the top of their respective stacks..”   Based upon: (Ting 2013, p. 25)

Virtual Machine Register SP

“SP” = “Stack Pointer”   This register is used to maintain a pointer to Forth’s Parameter Stack
A very powerful and useful feature of the figForth SP is that it is the microprocessor’s stack pointer, too

A detailed discussion of figForth’s SP Register…

Virtual Machine Register RP

“RP” = “Return Stack Pointer”   This register is the high-level figForth VM’s equivalent of the microprocessor’s “Program Counter” (“PC”) and keeps track of where the figForth VM is…

A detailed discussion of figForth’s RP Register…

Virtual Machine Register IP

“IP” = “Interpretive Pointer”

NEXT is a run-time routine of the address interpreter
IP usually points to the next word to be executed in a colon definition
After the current word is executed, the contents of IP is moved into W and now IP is incremented, pointing to the next word to be executed”
(Ting 2013, p. 26)   (my emphasis)

“Using the interpretive pointer IP alone would only allow the processing of a address list at a single level
The return stack is used as an extension of IP
When a colon definition calls other colon definitions, the contents of IP are saved on the return stack so that the IP can be used to call other definitions in the called colon definition
DOCOL thus provides the mechanism to nest indefinitely within colon definitions

Based on: (Ting 2013, p. 27)   (my emphasis)

Virtual Machine Register W

The “Working” Register W, contains the address of the current word to be executed
An indirect jump to the address in W starts the execution process of this word
In the mean time, W is also incremented to point to the parameter field address of the word being executed
Based on: (Ting 2013, p. 26)   (my emphasis)

Next Page: figForth’s Compilers

References:

Husband, D., 2011. M.Sc in IT (Software Engineering). Master’s thesis. University of Liverpool.

Husband, D., 2020. The New Forth Hardware Model. Baremetal Engineer Extraordinaire [online]. Available from: Http://baremetal.engineer/baremetal.software.engineer.pdf.

Knuth, D. E., 1997. The Art of Computer Programming - Vol 1 - Fundamental Algorithms - 3rd Ed.

Rather, E. D. and Moore, C. H., 1976. The Forth Approach to Operating Systems. ACM ’76: Proceedings of the 1976 annual conference. October 1976, Pages 233–240, https://doi.org/10.1145/800191.805586 [online]. Available from: Http://figforth.org.uk/library/p233-rather_The.Forth.Approach.to.Operating.Systems.pdf.

Schweller, K. G., 2003. Turing Machine. Available from: http://web.bvu.edu/faculty/schweller/Turing/Turing.html.

Taivalsaari, A., 2003. Virtual Machine Design. Available from: http://figforth.org.uk/library/VMDesign1.pdf.

Ting, C. H., 2013. Systems Guide to fig-Forth [online]. 3rd ed. San Mateo, CA 94402, USA: Offete Enterprises, Inc. Available from: http://figforth.org.uk/library/Systems.Guide.to.figForth.pdf.

Turing, A., 1936. The Turing Machine. Available from: http://introcs.cs.princeton.edu/java/52turing/.

  1. Surprise, surprise ! 

  2. And this website tries to explain and document all those things !! 

  3. And this this case I choose to use the Zilog eZ80 platform. See (Husband 2020) 

  4. And a design choice was made to operate the figForth “core” in 16-bit Z80 addressing mode and using mixed addressing “adl” mode as and when appropriate… Fun, fun, fun ! See (Husband 2020)  2


Updated: 6th March 2022 by David Husband
© 2021 David Husband, a.k.a. Baremetal Engineer Extraordinaire
All Rights Reserved – All Trademarks & Copyrights Acknowledged
All personal information is subject to the Data Protection Act 2018 & the UK GDPR
“ad auxilium aliis ad auxilium sibi”