Forth virtual machine register allocation
R3 - parameter stack (the 'X' register is
setup with a SEX 3 instruction)
R4 - return stack
R5 - i (interpreter pointer)
R6 - w (current 'word' pointer)
R8 - address of 'next', the inner interpreter
R9 - program counter
Code definitions
Forth words defined in assembly code should have the contents of their
code-field address (CFA) pointing to their parameter-field address
(PFA); the definition should terminate with the SEP 8 instruction
Inner interpreter mechanism, or 'next'
code words pass control to 'next' by setting R8 as the program counter (SEP
8)
when the inner interpreter has advanced the 'i' pointer and set the 'w'
pointer to the PFA of the next word to be executed then R9 is set as the
program counter to execute the code associated with that word and R8
will be reset to the start address of 'next' again
Stack requirements
stack space allocation is dictated by the application processing and
nesting requirements. If memory is restricted try some low nominal
values, eg. parameter stack space >= 40h bytes ? return stack space
>= 40h bytes ?
Header structure
the word header structure is based on the Forth-79 dictionary model:-
byte 1 - length L of
word name (msb
set)
[NFA]
byte 2.. - name bytes (final byte
indicated by msb set)
byte L+2 - 2byte link to NFA of previous named word in
dictionary
[LFA]
byte L+4 - 2byte pointer to code definition for this
word
[CFA]
byte L+6... - threaded list of 'word' addresses or parameter(s) for
definition [PFA]
Forth dictionary words used
standard Forth-79 words included in the monitor ROM dump:-
+ -
= > 0 2* 2/ @ and bl c@ c! drop dup not over rot swap
these definitions can be linked into the remainder of the full Forth
dictionary when it is present in ROM
Headerless structure
byte 1 - 2byte pointer to code definition for this
word
[CFA]
byte 3... - threaded list of 'word' addresses or parameter(s) for
definition [PFA]
Monitor commands
there are two commands:-
'A' - causes the monitor to wait for and accept a hex address terminated
by the 'Enter' character (0Dh); the monitor will then display the byte
content at that address. The contents of subsequent addresses can be
viewed without changing memory contents by using just the 'Enter' character to
step through addresses; memory contents can be changed by entering a new
hex value after the current byte contents are displayed and terminating
the new value using the 'Enter' character
(the 'ESC' character can be used to cancel the current input and
escape to the command prompt again)
'R' - causes the monitor to wait for and accept a hex address terminated
by the 'Enter' character ; the monitor will expect the address to be the
CFA of a Forth definition and will attempt to run it
(on the HHC the monitor is customised to pass control straight to the
full Forth system if the 'Enter' key is used directly at the command
prompt without entering one of the above commands)
Monitor ROM dump
edit the adresses in locations 12h-1Dh to customise the ROM dump for a
new system. The 2-byte locations should be filled as follows:-
[ 0010 - Monitor PFA (already contains 0309h, the monitor start
address) ]
0012 - Parameter stack (top address)
0014 - Return stack (top address)
0016 - 'key' CFA (routine to read 8bit ASCII value and place
on top of stack)
0018 - 'emit' CFA (routine to take 8bit ASCII value from stack and
write to display)
001A - 'page' CFA (routine to clear screen / form feed printer /
scroll display etc)
001C - 'init' CFA (routine to initialise I/O hardware)
001E - <reserved>
right-click here and
select 'Save Target As' to download
HHC_monitor_source.txt
a text file containing Forth source code for the HHC Forth-based monitor
If you only have access to an 1802 assembler, an assembly-based source version
of my Monitor hexdump has been generated courtesy of Herb Johnson and Lee Hart
(both very capable in 1802 hardware & software development);
click here (when link becomes available)
right-click here and
select 'Save Target As' to download
HHC_monitor_ROM.txt
a text file containing a hexdump of the HHC Forth-based monitor ROM
|