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