Close

When less is more

A project log for eForth for cheap STM8S gadgets

Turn cheap modules from AliExpress into interactive development kits!

thomasThomas 10/30/2016 at 12:420 Comments

eForth was designed to facilitate creating a Forth environment for a target computing architecture by someone who is fluent in assembly but new to the world of Forth (with fancy things like meta-compiling, extensible syntax, and multi-user environments).

This goal was achieved by coding a small number core words in assembly, and building interpreter, compiler, and all the rest out of those. However, many words are only useful for extending interpreter or compiler, or for create new structural words like SWITCH and CASE. When embedding Forth into a computing device this flexibility is rarely ever needed.

There are now new configuration flags to choose which of the base words for interpreter, compiler, or I/O and string handling should be visible in the dictionary. Most beginner won't need them, and an advanced user will know when adding them to the binary is required. There is a double benefit: a reduced footprint, and better usability!

In the default configuration the W1209 dictionary now shows the following words:

RAM NVM ADC@ ADC! OUT! P7S E7S BKEY LOCKF ULOCKF LOCK ULOCK
2C@ 2C! BSR 0= WORDS .S DUMP VARIABLE CREATE IMMEDIATE :
CALL, ] ; ." ABORT" AFT REPEAT WHILE ELSE THEN IF AGAIN
UNTIL BEGIN NEXT FOR LITERAL C, , ALLOT ' [ NAME? \ ( .(
? . U. U.R .R CR TYPE SPACES SPACE NUF? KEY DECIMAL HEX
ERASE FILL CMOVE @EXECUTE PAD 2@ 2! +! PICK 2/ 1- 1+ 2*
2- 2+ */ */MOD M* * UM* / MOD /MOD M/MOD UM/MOD WITHIN MIN
MAX < U< = ABS - DNEGATE NEGATE NOT + 2DUP 2DROP ROT ?DUP 
BG TIM -1 1 0 BL OUT BASE UM+ XOR OR AND 0< OVER SWAP DUP 
DROP >R R@ R> C@ C! @ ! EMIT ?KEY COLD

For the beginner this is much more readable, and removing 79 base words from the dictionary freed up almost 700 bytes for the application (the code is still there!).

But that's not all: I also rewrote some of the core code to take advantage of SP based addressing modes. This reduces Flash and RAM usage, makes the code cleaner, and also reduces the time for a context switch in background operation.

Now the bare-bones CORE target for an interactive Forth system requires just 4690 bytes, and the W1209 binary with background operation, compile to Flash, and 7S-Display fits in less than 5700 bytes (down from more than 6500 bytes).

I also looked into swapping the X and Y registers, which should free up about 170 bytes, but I won't do that until I have an automated regression tests for Forth core words.

Discussions