nanoFORTH  v2.2
n4_asm.h File Reference

nanoForth Assembler class More...

#include "n4.h"
Include dependency graph for n4_asm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 N4Asm
 

Macros

#define N4_DOES_META   1
 
#define N4_USE_GOTO   1
 
#define XT(a)   ((a) + sizeof(IU) + 3) /** adr + lnk[2] + name[3] */
 

Enumerations

enum  N4OP {
  TKN_IMM = 0, TKN_WRD, TKN_PRM, TKN_NUM,
  TKN_EXT, TKN_ERR
}
 
enum  N4_EXT_OP {
  I_NOP = 0, I_SEM = 10, I_DQ = 31, I_SQ = 32,
  I_DO = 55, I_I = 61, I_FOR = 62, I_LIT = 63
}
 

Functions

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...
 
N4OP N4Asm::parse (U8 *tkn, IU *rst, U8 run)
 Instruction decoder. More...
 
void N4Asm::compile (IU *rp0)
 Forth compiler. More...
 
void N4Asm::variable ()
 create a variable on dictionary More...
 
void N4Asm::constant (DU v)
 
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 ()
 
IU N4Asm::query ()
 dictionary, string list scanners More...
 
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 IU LFA_END = 0xffff
 end of link field More...
 
Opcode Masks
constexpr U8 CTL_BITS = 0xc0
 1100 0000, JMP - 11nn xxxx, PRM - 10nn nnnn, NUM - 0nnn nnnn More...
 
constexpr U8 JMP_OPS = 0xc0
 1100 0000 More...
 
constexpr U8 PRM_OPS = 0x80
 1000 0000 More...
 
constexpr U8 JMP_MASK = 0xf0
 11nn xxxx, nn - CALL 00, CDJ 01, UDJ 10, NXT 11 More...
 
constexpr U8 PRM_MASK = 0x3f
 00nn nnnn, 6-bit primitive opcodes More...
 
constexpr IU ADR_MASK = 0x0fff
 0000 aaaa aaaa aaaa 12-bit address in 16-bit branching instructions More...
 
Opcode Prefixes
constexpr U8 OP_CALL = 0xc0
 1100 0000 More...
 
constexpr U8 OP_CDJ = 0xd0
 1101 0000 More...
 
constexpr U8 OP_UDJ = 0xe0
 1110 0000 More...
 
constexpr U8 OP_NXT = 0xf0
 1111 0000 More...
 

Detailed Description

nanoForth Assembler class

nanoForth Opcode formats

branching : 11BB oooo oooo oooo (12-bit absolute address)
primitive : 10cc cccc (64 primitives)
3-byte lit: 1011 1111 nnnn nnnn nnnn nnnn bf xxxx xxxx (16-bit signed integer)
1-byte lit: 0nnn nnnn (0..127)
n-byte str: len, byte, byte, ... (used in print str i.e. .")

Macro Definition Documentation

◆ N4_DOES_META

#define N4_DOES_META   1

@Note 1: N4_DOES_META flag enable meta-programming, it takes 6 opcodes slots i.e. 55~60 can be disabled if other opcodes need the slots @Note 2: N4_USE_GOTO flag use computed goto for primitive word invocation, speeds up 5%, but takes extra 128 bytes of RAM, can be disabled if some library needs extra memory enable meta programming

◆ N4_USE_GOTO

#define N4_USE_GOTO   1

use computed goto

◆ XT

#define XT (   a)    ((a) + sizeof(IU) + 3) /** adr + lnk[2] + name[3] */

Enumeration Type Documentation

◆ N4OP

enum N4OP

parser actions enum used by execution and assembler units

Enumerator
TKN_IMM 

immediate word

TKN_WRD 

colon (user defined) word

TKN_PRM 

primitive built-in word

TKN_NUM 

number (literal)

TKN_EXT 

extended built-in word

TKN_ERR 

parse error (unknown token)

◆ N4_EXT_OP

enum N4_EXT_OP

opcodes for loop control (in compiler mode) Note: sequence in-sync with N4Asm::N4_WORDS, and N4VM::_invoke

Enumerator
I_NOP 

extended opcode (used by for...nxt loop)

NOP means EXIT

I_SEM 

; semi-colon

I_DQ 

." dot_string

I_SQ 

S" do_string.

I_DO 

DO>

I_I 

61, loop counter

I_FOR 

62

I_LIT 

63 = 0x3f 3-byte literal

Variable Documentation

◆ CTL_BITS

constexpr U8 CTL_BITS = 0xc0
constexpr

1100 0000, JMP - 11nn xxxx, PRM - 10nn nnnn, NUM - 0nnn nnnn

◆ JMP_OPS

constexpr U8 JMP_OPS = 0xc0
constexpr

1100 0000

◆ PRM_OPS

constexpr U8 PRM_OPS = 0x80
constexpr

1000 0000

◆ JMP_MASK

constexpr U8 JMP_MASK = 0xf0
constexpr

11nn xxxx, nn - CALL 00, CDJ 01, UDJ 10, NXT 11

◆ PRM_MASK

constexpr U8 PRM_MASK = 0x3f
constexpr

00nn nnnn, 6-bit primitive opcodes

◆ ADR_MASK

constexpr IU ADR_MASK = 0x0fff
constexpr

0000 aaaa aaaa aaaa 12-bit address in 16-bit branching instructions

◆ OP_CALL

constexpr U8 OP_CALL = 0xc0
constexpr

1100 0000

◆ OP_CDJ

constexpr U8 OP_CDJ = 0xd0
constexpr

1101 0000

◆ OP_UDJ

constexpr U8 OP_UDJ = 0xe0
constexpr

1110 0000

◆ OP_NXT

constexpr U8 OP_NXT = 0xf0
constexpr

1111 0000

◆ LFA_END

constexpr IU LFA_END = 0xffff
constexpr

end of link field

primitive
static void primitive(unsigned char ic)
Definition: tforth.c:442