nanoFORTH  v2.2
n4_asm.h
Go to the documentation of this file.
1 
15 #ifndef __SRC_N4_ASM_H
16 #define __SRC_N4_ASM_H
17 #include "n4.h"
28 #define N4_DOES_META 1
29 #define N4_USE_GOTO 1
30 enum N4OP {
34  TKN_IMM = 0,
40 };
44 constexpr U8 CTL_BITS = 0xc0;
45 constexpr U8 JMP_OPS = 0xc0;
46 constexpr U8 PRM_OPS = 0x80;
47 constexpr U8 JMP_MASK = 0xf0;
48 constexpr U8 PRM_MASK = 0x3f;
49 constexpr IU ADR_MASK = 0x0fff;
50 constexpr U8 OP_CALL = 0xc0;
54 constexpr U8 OP_CDJ = 0xd0;
55 constexpr U8 OP_UDJ = 0xe0;
56 constexpr U8 OP_NXT = 0xf0;
57 enum N4_EXT_OP {
63  I_NOP = 0,
64  I_SEM = 10,
65  I_DQ = 31,
66  I_SQ = 32,
67  I_DO = 55,
68  I_I = 61,
69  I_FOR = 62,
70  I_LIT = 63
71 };
72 constexpr IU LFA_END = 0xffff;
73 #define XT(a) ((a) + sizeof(IU) + 3)
74 namespace N4Asm // (10-byte header)
84 {
85  extern U8 *last;
86  extern U8 *here;
87 
88  // EEPROM persistence I/O
89  void save(U8 autorun=0);
90  IU load(U8 autorun=0);
91 
92  IU reset();
93 
95  N4OP parse(
96  U8 *tkn,
97  IU *rst,
98  U8 run
99  );
101  void compile(
102  IU *rp0
103  );
104  void variable();
105  void constant(DU v);
106  void create();
108  void comma(DU v);
109  void ccomma(DU v);
110  void does(IU xt);
111  void dot_str();
113  IU query();
114  void words();
115  void forget();
116  void see();
117 
119  U16 trace(
120  IU adr,
121  U8 ir,
122  char delim=0
123  );
124 }; // namespace N4Asm
125 
126 #endif //__SRC_N4_ASM_H
N4Asm::does
void does(IU xt)
compile a 16-bit value onto dictionary
Definition: n4_asm.cpp:404
I_LIT
@ I_LIT
63 = 0x3f 3-byte literal
Definition: n4_asm.h:70
N4Asm::save
void save(U8 autorun)
persist user dictionary to EEPROM
Definition: n4_asm.cpp:217
JMP_MASK
constexpr U8 JMP_MASK
11nn xxxx, nn - CALL 00, CDJ 01, UDJ 10, NXT 11
Definition: n4_asm.h:47
N4OP
N4OP
Definition: n4_asm.h:33
N4Asm::here
U8 * here
top of dictionary (exposed to _vm for HRE, ALO opcodes)
Definition: n4_asm.cpp:98
OP_CDJ
constexpr U8 OP_CDJ
1101 0000
Definition: n4_asm.h:54
N4Asm::ccomma
void ccomma(DU v)
compile a 16-bit value onto dictionary
Definition: n4_asm.cpp:403
JMP_OPS
constexpr U8 JMP_OPS
1100 0000
Definition: n4_asm.h:45
TKN_IMM
@ TKN_IMM
immediate word
Definition: n4_asm.h:34
TKN_NUM
@ TKN_NUM
number (literal)
Definition: n4_asm.h:37
I_I
@ I_I
61, loop counter
Definition: n4_asm.h:68
compile
static void compile(void)
Definition: tforth.c:223
N4Asm::reset
IU reset()
reset internal pointers (for BYE)
Definition: n4_asm.cpp:297
TKN_PRM
@ TKN_PRM
primitive built-in word
Definition: n4_asm.h:36
OP_NXT
constexpr U8 OP_NXT
1111 0000
Definition: n4_asm.h:56
N4Asm::constant
void constant(DU v)
Definition: n4_asm.cpp:435
N4Asm::words
void words()
display words in dictionary
Definition: n4_asm.cpp:450
N4Asm::comma
void comma(DU v)
compile a 16-bit value onto dictionary
Definition: n4_asm.cpp:402
N4Asm::parse
N4OP parse(U8 *tkn, IU *rst, U8 run)
Instruction decoder.
Definition: n4_asm.cpp:325
I_SEM
@ I_SEM
; semi-colon
Definition: n4_asm.h:64
I_SQ
@ I_SQ
S" do_string.
Definition: n4_asm.h:66
N4Asm::create
void create()
meta compiler
Definition: n4_asm.cpp:389
PRM_OPS
constexpr U8 PRM_OPS
1000 0000
Definition: n4_asm.h:46
TKN_ERR
@ TKN_ERR
parse error (unknown token)
Definition: n4_asm.h:39
N4_EXT_OP
N4_EXT_OP
Definition: n4_asm.h:62
DU
S16 DU
16-bit data unit (CELL)
Definition: n4.h:76
I_NOP
@ I_NOP
extended opcode (used by for...nxt loop)
Definition: n4_asm.h:63
N4Asm::load
U16 load(U8 autorun)
restore user dictionary from EEPROM
Definition: n4_asm.cpp:256
I_DQ
@ I_DQ
." dot_string
Definition: n4_asm.h:65
N4Asm::dot_str
void dot_str()
Definition: n4_asm.cpp:416
PRM_MASK
constexpr U8 PRM_MASK
00nn nnnn, 6-bit primitive opcodes
Definition: n4_asm.h:48
TKN_WRD
@ TKN_WRD
colon (user defined) word
Definition: n4_asm.h:35
N4Asm::see
void see()
decode colon word
Definition: n4_asm.cpp:478
U16
uint16_t U16
16-bit unsigned integer, for return stack, and pointers
Definition: n4.h:66
variable
static void variable(void)
Definition: tforth.c:340
I_FOR
@ I_FOR
62
Definition: n4_asm.h:69
ADR_MASK
constexpr IU ADR_MASK
0000 aaaa aaaa aaaa 12-bit address in 16-bit branching instructions
Definition: n4_asm.h:49
OP_UDJ
constexpr U8 OP_UDJ
1110 0000
Definition: n4_asm.h:55
LFA_END
constexpr IU LFA_END
end of link field
Definition: n4_asm.h:72
forget
static void forget(void)
Definition: tforth.c:376
CTL_BITS
constexpr U8 CTL_BITS
1100 0000, JMP - 11nn xxxx, PRM - 10nn nnnn, NUM - 0nnn nnnn
Definition: n4_asm.h:44
N4Asm::last
U8 * last
pointer to last word, for debugging
Definition: n4_asm.cpp:97
I_DO
@ I_DO
DO>
Definition: n4_asm.h:67
U8
uint8_t U8
8-bit unsigned integer, for char and short int
Definition: n4.h:65
N4Asm::trace
IU trace(IU a, U8 ir, char delim)
print execution tracing info
Definition: n4_asm.cpp:500
TKN_EXT
@ TKN_EXT
extended built-in word
Definition: n4_asm.h:38
N4Asm::query
IU query()
dictionary, string list scanners
Definition: n4_asm.cpp:314
OP_CALL
constexpr U8 OP_CALL
1100 0000
Definition: n4_asm.h:53
N4Intr::ir
IsrRec ir
real-time interrupt record
Definition: n4_intr.cpp:20
n4.h
nanoForth main controller
IU
U16 IU
16-bit instruction unit (ADDR)
Definition: n4.h:75