SIMPL: A subset of Forth

A project log for SIMPL

Serial Interpreted Minimal Programming Language for exploring microcontrollers & new cpu architectures

monsonitemonsonite 4 days ago0 Comments

As SIMPL evolved it became clear that the Txtzyme command interpreter with only 13 basic commands for exercising peripheral hardware could be developed further into a virtual machine with its own tailored instruction set. 

From an early stage in development it was decided that the VM instructions would be single character printable ascii codes. This was done initially to make the language more human readable, and was well suited the serial terminal interface. 

The extensions to Txtzyme allowed SIMPL commands to be executed from RAM, and each of these commands had an accompanying command action stored as inline code in the Flash ROM.

This transition from instructions in RAM, executing blocks of code contained in ROM effectively released the microcontroller from the constraints of the Harvard architecture by using a Von Neumann virtual machine.

SIMPL and Forth

SIMPL has been greatly influenced by the Forth language developed by Charles H. Moore between 1958 and 1970. During the 1970s it was ported onto a wide range of minicomputers and microcomputers. It is a compact and extensible stack-based language.

The stack based machine is the obvious candidate for executing the Forth language as it matches the needs of the Forth machine model.

As SIMPL is a subset of Forth, it would seem sensible to make the SIMPL VM a stack based architecture.

Traditionally Forth was based around a 16-bit wordsize and a 16-bit addressing range that was commonplace amongst mini computers in the 1970s.  

Chuck Moore and Dr. C.H. Ting worked together in the 1990s to create a minimal instruction set computer (MISC) which could efficiently execute Forth primitive instructions. Moore and Ting identified that Forth could be effectively synthesised from 32 or fewer primitive instructions.
Chen-Hanson Ting developed an eForth model, which was a formal specification for a Forth, implemented from a set of 32 primitives.

Chuck Moore took on the hardware design challenge of MISC Forth processors, and developed a series of designs characterised by small instruction sets and minimal hardware.

A full sized Forth implemantation would typically be around 6K bytes.

SIMPL proposes the use of a stack-based virtual machine, implementing a small number of primitive instructions which allow an extensible language to be created. It is suggested that the SIMPL machine can be inplemented in about  1 to 2K bytes of Flash memory depending on the target microcontroller.

Forth on an 8-Bit AVR

A tiny Forth with 28 primitives may be implemented in about 2K bytes of AVR assembly language. This implementation is by T. Nakagawa of Japan.

To implement Forth on an 8-bit AVR microcontroller requires an average of about 10 AVR assembly language instructions to implement each primitive.  There is also the overhead of the interpreter. This slows the execution speed down by a factor of 10 or 20. On the 20MHz AVR this corresponds to about 1 million Forth instructions per second (FIPS).