Which Forth?

2 minute read

Where I discuss several versions of Forth and the attributes of each.

Forth Versions

There are many versions of Forth. This is due to a variety of reasons:

  1. Forth as a language is over 60 years old, hence there has been a significant amount of time for it to evolve.
  2. Forth tends to be processor-focused. Some people might argue this point, however, due to Forth’s ability to work well at a low-level, implementations tend to be aimed at a particular processor than other high-level languages.
  3. Forth is a relatively easy language to write and it is extensible, which means its not unusual for someone to “roll their own version”.

To date, I have focused on two specific versions:

  1. CH Ting’s Forth Virtual Machine version, ESPForth
  2. Mikael Nordman’s FlashForth

ESPForth

If you are new to Forth, I highly recommend ESPForth. CH Ting provides great documentation and provides details as to why he does what he does with Forth. He is prolific with the types of processors for which he has implemented Forth as well as the documentation he creates for each Forth.

ESPForth is an interpreted Forth that runs via Forth Virtual Machine (FVM). This isn’t necessarily bad, as the ESP32 boards are absurdly fast and powerful. And it allows you to use a hybrid environment for working with Forth. Its not difficult to create a Forth word that calls the underlying FreeRTOS/Arduino framework as compared to having to write everything in Forth.

Finally, if you want to do something else with your ESP32 board, you can. Load the board with new code and you have an extremely powerful C++ microcontroller available.

FlashForth

I believe this is a great Forth for exploring using Forth for embedded computing. It is available for several microcontrollers AVR ATmega328p, Microchip PIC18F and PIC24-33. The first two are 8-bit and the last is 16-bit. As FlashForth is based on assembly code, it is quite fast even on the lowly and ancient ATmega328p. I have an example which shows FF running via the Forth assembly code running “bit-bang” at 3.2Mhz, which is quite fast!

Having an 8-bit processor simplifies programming and allows you to become proficient in Forth without the overhead of more complicated 16-bit and 32-bit microcontrollers. The Arduino-Forth website is excellent and provides a great number of examples.

Comments powered by Talkyard.