[OpenBIOS] Help with local variables

Mark Cave-Ayland mark.cave-ayland at siriusit.co.uk
Wed Feb 24 11:13:23 CET 2010

G 3 wrote:

> Hi, I am working on implementing local variable support in OpenBIOS. I 
> have done a lot of research on the issue, but there are a few issues I 
> still need help resolving. 
> -Does Openbios context switch when a word is called? This is when all 
> the registers are saved into a stack frame, so the currently executing 
> word can use them.

I think you are looking too low a level here - all of this is handled 
automatically by the Forth engine.

> -Could someone give me a tutorial on how to add c functions to forth and 
> make them accessible to the interpreter. I want to be able to add words 
> to the dictionary and be able to use them from the command line.

The easiest way to look at this is to look at one of the existing 
primitive words such as DOCOL. But in short:

- Add the new word to the end of the wordnames array in kernel/bootstrap.c

- Add the C function name to the end of the words array in 

- Add the C function to kernel/internal.c

> - Would anyone know which register on the PowerPC would be good for 
> using as a stack pointer for a new local variable stack? I think r13 is 
> free and a possible candidate. 

Again, you're looking at too low a level here. What I believe you need 
to do is create a word that adds a new dictionary to the search list at 
the start of the function, much in the same way that a package instance 



Mark Cave-Ayland - Senior Technical Architect
PostgreSQL - PostGIS
Sirius Corporation plc - control through freedom
t: +44 870 608 0063

Sirius Labs: http://www.siriusit.co.uk/labs

More information about the OpenBIOS mailing list