nanoFORTH  v2.2
n4_asm.cpp File Reference

nanoForth Assmebler implementation More...

#include "n4_asm.h"
#include <EEPROM.h>
#include "n4_core.h"
Include dependency graph for n4_asm.cpp:

Namespaces

 N4Asm
 

Macros

Branching
#define JMP00(j)   ENCA(here, (j)<<8)
 
#define JMPTO(idx, f)   ENCA(here, (idx) | ((f)<<8))
 
#define JMPSET(idx, p1)
 
Stack Ops (note: return stack grows downward)
#define RPUSH(a)   (*(vm.rp++)=(IU)(a))
 
#define RPOP()   (*(--vm.rp))
 
Dictionary Index <=> Pointer Converter
#define DIC(n)   ((U8*)dic + (n))
 
#define IDX(p)   ((IU)((U8*)(p) - dic))
 

Functions

U8 N4Asm::_find (U8 *tkn, IU *adr)
 search the keyword through colon word linked-list More...
 
void N4Asm::_add_word ()
 
void N4Asm::_add_branch (U8 op)
 
void N4Asm::_add_str ()
 
void N4Asm::_list_voc (U16 n)
 
void N4Asm::save (U8 autorun=0)
 persist user dictionary to EEPROM More...
 
U16 N4Asm::load (U8 autorun=0)
 restore user dictionary from EEPROM More...
 
IU N4Asm::reset ()
 reset internal pointers (for BYE) More...
 
IU N4Asm::query ()
 dictionary, string list scanners More...
 
N4OP N4Asm::parse (U8 *tkn, IU *rst, U8 run)
 Instruction decoder. More...
 
void N4Asm::compile (IU *rp0)
 Forth compiler. More...
 
void N4Asm::create ()
 meta compiler More...
 
void N4Asm::comma (DU v)
 compile a 16-bit value onto dictionary More...
 
void N4Asm::ccomma (DU v)
 

compile a 16-bit value onto dictionary

More...
 
void N4Asm::does (IU xt)
 

compile a 16-bit value onto dictionary

More...
 
void N4Asm::dot_str ()
 
void N4Asm::variable ()
 create a variable on dictionary More...
 
void N4Asm::constant (DU v)
 
void N4Asm::words ()
 display words in dictionary More...
 
void N4Asm::forget ()
 forgets word in the dictionary More...
 
void N4Asm::see ()
 decode colon word More...
 
IU N4Asm::trace (IU adr, U8 ir, char delim=0)
 print execution tracing info More...
 

Variables

constexpr U16 N4_SIG = (((U16)'N'<<8)+(U16)'4')
 EEPROM signature. More...
 
constexpr U16 N4_AUTO = N4_SIG | 0x8080
 EEPROM auto-run signature. More...
 
constexpr U16 ROM_HDR = 6
 EEPROM header size. More...
 
constexpr U8 WORDS_PER_ROW = 16
 words per row when showing dictionary More...
 
U8N4Asm::last { NULL }
 pointer to last word, for debugging More...
 
U8N4Asm::here { NULL }
 top of dictionary (exposed to _vm for HRE, ALO opcodes) More...
 
U8 N4Asm::tab = 0
 

nanoForth built-in vocabularies

* make utilities available

#define N4_WORDS
 
const PROGMEM char IMM []
 
const PROGMEM char JMP []
 words for branching ops in compile mode. More...
 
const PROGMEM char PRM []
 primitive words (53 of 61 allocated, 3 pre-allocated). More...
 
const PROGMEM char PMX [] = "\x2" "I " "FOR"
 loop control opcodes Note: Standard Forth VAL - CONSTANT DLY - MS NOT - INVERT NXT - NEXT, but break at 1 More...
 

Detailed Description

nanoForth Assmebler implementation

Assembler Memory Map:

mem[...dic_sz...[...stk_sz...]
| | |
+-dic--> +-->sp rp<--+

Macro Definition Documentation

◆ N4_WORDS

#define N4_WORDS
Value:
" " "TRC" "ROT" "OVR" "SWP" "DUP" "DRP" "LSH" "RSH" "NOT" \
"XOR" "OR " "AND" "RND" "MIN" "MAX" "ABS" "MOD" "NEG" "/ " \
"* " "- " "+ " "= " "< " "> " "<> " "KEY" "EMT" "CR " \
". " ".\" ""S\" ""TYP" "HRE" ">R " "R> " "! " "@ " "C! " \
"C@ " "ALO" "DNG" "D- " "D+ " "CLK" "DLY" "PWM" "OUT" "AIN" \
"IN " "PIN" "PCE" "TME" "API"

◆ JMP00

#define JMP00 (   j)    ENCA(here, (j)<<8)

◆ JMPTO

#define JMPTO (   idx,
 
)    ENCA(here, (idx) | ((f)<<8))

◆ JMPSET

#define JMPSET (   idx,
  p1 
)
Value:
do { \
U8 *p = DIC(idx); \
U8 f8 = *(p); \
IU a = IDX(p1); \
ENCA(p, (a | (IU)f8<<8)); \
} while(0)

◆ RPUSH

#define RPUSH (   a)    (*(vm.rp++)=(IU)(a))

push address onto return stack

◆ RPOP

#define RPOP ( )    (*(--vm.rp))

pop address from return stack

◆ DIC

#define DIC (   n)    ((U8*)dic + (n))

convert dictionary index to a memory pointer

◆ IDX

#define IDX (   p)    ((IU)((U8*)(p) - dic))

convert memory pointer to a dictionary index

Variable Documentation

◆ IMM

const PROGMEM char IMM[]
Initial value:
= "\xf"
": " "VAL" "VAR" "PCI" "TMI" "SEX" "SAV" "LD " "FGT" "DMP"
"SEE" "WRD" "DEC" "HEX" "BYE"

◆ JMP

JMP
Initial value:
= "\x0b"
"THN" "ELS" "IF " "RPT" "UTL" "WHL" "BGN" "NXT" "I " "FOR"
"; "

words for branching ops in compile mode.

◆ PRM

PRM
Initial value:
=
"\x3d" N4_WORDS "DO>" "CRE" "EXE" "' " ", " "C, "

primitive words (53 of 61 allocated, 3 pre-allocated).

◆ PMX

PMX = "\x2" "I " "FOR"

loop control opcodes Note: Standard Forth VAL - CONSTANT DLY - MS NOT - INVERT NXT - NEXT, but break at 1

◆ N4_SIG

constexpr U16 N4_SIG = (((U16)'N'<<8)+(U16)'4')
constexpr

EEPROM signature.

◆ N4_AUTO

constexpr U16 N4_AUTO = N4_SIG | 0x8080
constexpr

EEPROM auto-run signature.

◆ ROM_HDR

constexpr U16 ROM_HDR = 6
constexpr

EEPROM header size.

◆ WORDS_PER_ROW

constexpr U8 WORDS_PER_ROW = 16
constexpr

words per row when showing dictionary

dic
static unsigned char dic[DIC_SIZE]
Definition: tforth.c:31
DIC
#define DIC(n)
Definition: n4_asm.cpp:87
N4_WORDS
#define N4_WORDS
Definition: n4_asm.cpp:49
IDX
#define IDX(p)
Definition: n4_asm.cpp:88
IU
U16 IU
16-bit instruction unit (ADDR)
Definition: n4.h:75