Inside the PIC TLM-Forth

The preface to the Win32for manual in the file STARTUP.TXT gives a brief history of this interesting language.

Forth has been used much more widely that many people think. The reason that it is not recognised is that the applications are embedded into products. This package, it is hoped, will continue this tradition.

The features and implementation of the Win32for Forth, given in the Win32for manual introduction, are not quite the same as the implementation in TLM. The fundamental difference is the architecture of the different processors, MSP430 v 80X86. The IRTC compiles subroutine threaded code and optimises the constant use and some operations.

Inside Forth

A detailed description of the TLM Forth is given here to assist those wishing to use code definitions in particular. The so called Forth inner interpreter, NEXT, and the associated call, NEST, and return, UNNEST, definitions make up the Forth machine.

NEXT

This is the heart of a Forth machine. In a subroutine threaded Forth NEXT is a CALL instruction. The return address is placed on the return stack by the processor, the address called is called the Code Field Address, CFA.

NEST

Every high level Forth word is a subroutine. It is called and the CFA points to the code. The IRTC compiler keeps track of the Forth words and compiles CALL # instructions to call each word used within a definition.

Each Forth word starts with a :

EXIT

Every NEST must EXIT, as every Jump to Subroutine must Return from Subroutine. The value on top of the System Stack is popped by a RET instruction that is compiled by the ; at the end of each Forth word definition.

Data Stack

Forth is a stack based language. The Return Stack used for calls and returns has been described above. The Data that is to be manipulated is placed on the Data Stack. The processor's R5 is used to control this stack. The TLM does however, have an unusual feature. The top Data Stack item is always in the R7. The Data Stack controlled by R5 containing any items below this. In a machine code definitions any of the registers R4 - R8 must be saved if they are required by the definition, and restored if the definition itself does not affect the Data Stack. This is most easily done by pushing out onto the Return Stack at the beginning of the definition. For use by the tasks, a USER location, SP0, is reserved for saving the Return Stack pointer, the Data Stack pointer is saved on the Return Stack.

Code and Variable Space

In an MSP430 embedded system the Code space is in Flash memory. The Variables must therefore have a RAM area for their contents. These two spaces are controlled by different words.

The Code space is set by ORG. This is similar to the construct in assemblers.

 Use: $F000 ORG

The address $F000 is set in MSP430 xxxx.INI. It is the beginning of the Target development code space.

The Variable space is set by VORG.

 Use: $0220 VORG

Tests on the validity of the memory spaces are done at compile time. The following VALUEs may be altered to reflect your memory by editing MSP xxxx.INI:

ROM-START set to $F000

ROM-END set to $FFFF

RAM-START set to $0220

RAM-END set to $02A8

examples are for the MSP430F1121

Contents