wordlists, vocabularies, vocabulary prefixes and implicit context switching

A big Thank You to [manfredmahlow] for creating Vocabularies for Mecrisp-Stellaris !

Software Versions used in this demo

  • The latest Mecrisp-Stellaris https://sourceforge.net/projects/mecrisp/files/mecrisp-stellaris-2.3.9a.tar.gz is required to use Manfred Mahlow’s VOCS which is included in the common/experimental/vocs-0.7.0 directoru of the release.

  • Howto’s include :-
    • VOC-HOWTO-Classes-1: Shows some basics of VOCs based OOP.
    • VOC-HOWTO-Classes-2: How to create classes, using instance variables, defined in other classes.
    • VOC-HOWTO-DataTypes: A short demo to show how VOCs can be used to define data types.
    • VOC-HOWTO-Registers: Using VOCs to implement register identifiers.


This shows how vocabularies easily enable the use of phrases such as ” GPIOA MODER9 ? ” as a alternative to non vocabulary words like ” GPIOA-MODER9? ” along with the economy of OOP and a possible 50% reduction in Flash memory usage for Peripheral and Register definitions.

  • A stm32F0 GPIO has eleven+ registers that configure and control it.
  • The one which controls whether a GPIO bit is IN, OUT, SPECIAL FUNCTION or ANALOG is named the ‘MODER’ register , which means ‘MODE REGISTER’.
  • Each GPIO pin (or bit) in MODER is controlled by a 2bit pair, as shown in the list below.
gpioa. GPIOA_MODER (read-write) $28280000
00 10 10 00 00 10 10 00 00 00 00 00 00 00 00 00

These are the 2bit GPIO MODES ( % = binary base ) as used in the GPIOA MODER REGISTER above:-

%00 constant IN          ( INPUT MODE )
%01 constant OUT         ( OUTPUT MODE )
%11 constant ANALOG      ( ANALOG MODE )

Each GPIO port is 16 bits ( GPIOA0 - GPIOA15 ), and each bit requires a 2bit code in the MODER REGISTER, making the MODER REGISTER 32 bits long.

Using Manfred’s ‘Vocabularies’. The GPIOA MODER register may be read as below. Note: this is a working Mecrisp-Stellaris system and some bits are already set and must not be changed. This all happens in real time in the MCU.

GPIOA MODER @ bin. 101000001010000000000000000000  ok.   ( '@' means 'fetch' and 'bin.' means 'display the result in binary' )

Set GPIOA BIT 1 to ANALOG MODE ( %11 ) ..

ANALOG GPIOA MODER1 !  ok  ( "!" means store )

Check GPIOA MODER to see what the new value is ...

GPIOA MODER @ bin. 101000001010000000000000001100  ok.

The GPIOA MODER1 value is also easily read ..

GPIOA MODER1 @ . 3  ok.

Or use the alternate ”?” to display the MODE ( my favorite )

GPIOA MODER1 ? %11  ok.
GPIOA MODER0 ? %0  ok.

Bingo, GPIOA BIT 1 is now in ‘ANALOG’ MODE ( %11 ) and all other bits are unchanged.

Now change GPIOA BIT 1 to INPUT MODE ( %00 ) ..


Check the change occured ..

GPIOA MODER @ bin. 101000001010000000000000000000  ok.

Or ..

GPIOA MODER1 ? %0  ok.

GPIOA BIT 1 is now reset to %00 (INPUT MODE) and the other bits are unchanged.


Forth is often criticized for being terse, cryptic or hard, but if we compare our port MODE syntax with that of Arduino (C language), is Forth really harder, perhaps it’s easier ?

Forth - Arduino Comparison, INPUT

Set a Port Pin to INPUT MODE Code Comments
Forth on STM32F0 IN GPIOA MODER1 ! Set GPIOA bit 1 to INPUT. When the <enter> key is pressed this command will instantly take effect on the target hardware.
Arduino pinMode(pin, INPUT); set pin to INPUT. ‘pin’ can have a value of 0 - 13. The code must first be compiled and then uploaded to the target.

Forth - Arduino Comparison, OUTPUTS

Set all PORT pins to OUTPUTS Code Comments
Forth on STM32F0 %01010101010101010101010101010101 GPIOB MODER ! Easy, GPIOB BITS 0 - 15 are now all OUTPUT.
Arduino int a; for(a=0;a < 13;a++){ pinMode(a, OUTPUT); } Which port is ‘pin’ ? On the UNO, ‘pin’ has a value of 0 - 13 and is spread across Ports B and D, so if you want them all to be OUTPUTS, then code like this is required, or you have to refer to the databook and configure each pin individually.