eForth1
v2.4
|
eForth Assembler module More...
#include "eforth_asm.h"
Macros | |
#define | WORDS_ROW_WIDTH 0x44 /** WORDS row width control */ |
Functions | |
int | assemble (U8 *rom) |
void | _dump_rom (U8 *rom, int len) |
Variables | |
eForth Assembler module variables | |
IU | PC |
assembler program counter More... | |
U8 | R |
assembler return stack index More... | |
U8 * | _byte |
assembler byte array (heap) More... | |
IU | _link |
link to previous word More... | |
Compiled Address for Branching | |
IU | DOTQP |
addr of output ops, used by _dotq, _strq, _abortq More... | |
eForth Assembler module
Forth Macro Assembler Note: TODO: adding Leo Brodie's words
#define WORDS_ROW_WIDTH 0x44 /** WORDS row width control */ |
int assemble | ( | U8 * | rom | ) |
eForth Macro Assembler
ROM starting address
reserved for COLD boot vector
Kernel dictionary (primitive words)
( u ul uh – f ) check 3rd item within [ul uh)
( udl udh u – ur uq ) unsigned double divided by a single
( u1 u2 – ud ) unsigned double = multiply unsigned singles
( n1 n2 – d ) double = single * single
( n1 n2 – sum c ) add two numbers and carry flag
( n1 n2 n – r q ) multiply n1 n2 div/mod by a single
( n1 n2 – r q ) single devide
( n1 n2 n3 – q ) multiply n1 n2 divide by n3 return quotient
( n – dl dh )
( dl dh – n )
extended words
base of data stack (fixed instead of user var)
address of stack pointer
(TODO: add J)
( f – ) enable/disable debug tracing
( – ) save user variables and dictionary to EEPROM
( – ) restore user variables and dictionary from EERPROM
( n – ) call a C-function vector
Kernel constants
- 'TIB console input buffer pointer
- BASE current radix for numeric ops
- CP, top of dictionary, same as HERE
- CONTEXT name field of last word
- LAST, same as CONTEXT
- 'MODE ('TEVAL - interpreter or compiler)
- ABORT exception rescue handler (QUIT)
- HLD char pointer to output buffer
- SPAN number of character accepted
- >IN interpreter pointer to next char
- #TIB number of character received in TIB
- tmp storage (alternative to return stack)
Console Input and Common words
Number Conversions and formatting
TODO: add >NUMBER
Console Output
TODO: add PAGE
Parsing
Dictionary serach
TODO: add COMPARE
Terminal Input
Text Interpreter
QUERY/TIB/ACCEPT - start the interpreter loop <-------<------. TOKEN/PARSE - get a space delimited word . EXECUTE - attempt to look up that word in the dictionary . NAME?/find - was the word found? ^ |-Yes: | | $INTERPRET - are we in compile mode? | | |-Yes: ^ | | \-Is the Word an Immediate word? | | | |-Yes: | | | | \- EXECUTE Execute the word -------------------->. | | | | | | | | \- if (NAME?) EXECU else NUMBQ ---------------->. | | \-No: | | | \-Compile the word into the dictionary --------->. | \-No: | | \- EXECUTE Execute the word ----->------------------->. \-No: ^ NUMBER? - Can the word be treated as a number? | |-Yes: | | \-Are we in compile mode? | | |-Yes: | | | | | | | \-Compile a literal into the dictionary >--------->. | | | | \-No: | | | | | \-Push the number to the variable stack >--------->. \-No: . \-An Error has occurred, prIU out an error message ->
TODO: add ?STACK
Colon Compiler
TODO: add [']
Debugging Tools
Optional: Takes ~300 bytes ROM space
display address with colon delimiter ( a – )
display opcode at given address ( a0 op – a1 )
Control Structures
- BEGIN...AGAIN, BEGIN... f UNTIL, BEGIN...(once)...f WHILE...(loop)...REPEAT
- f IF...THEN, f IF...ELSE...THEN
- n FOR...NEXT, n FOR...(first)... f AFT...(2nd,...)...THEN...(every)...NEXT
TODO: add DO...LOOP, +LOOP, LEAVE
String Literals
Defining Words - variable, constant, and comments
change runtime behavior to following code
( ra ca ) para on return stack, offset to defining word
TODO: add POSTPONE
Comments
Lexicon Bits
Arduino specific opcodes
( – ud ud ) get current clock (in ms)
( n p – ) set pinMode(p, n=1:OUTPUT, n=0: INPUT)
( h l p – ) set map range to pin
( p – n ) digitalRead(p)
( n p – ) digitialWrite(p, n=1 HIGH, n=0 LOW)
( p – n ) read analog value from pin
( n p – ) set duty cycle % (PWM) to pin
( xt n – ) on timer interrupt calls xt every n ms
( xt p – ) on pin change interrupt calls xt
( f – ) enable/disable timer interrupt
( f – ) enable/disable pin change interrupt
Cold Start address (End of dictionary)
Boot Vector Setup
void _dump_rom | ( | U8 * | rom, |
int | len | ||
) |
create C array dump for ROM