nFORTH v2.3
- To: "my" <mplichot@xxxxxxxxx>, "David Cary" <d.cary@xxxxxxxx>, "misc" <MISC>
 
- Subject: nFORTH v2.3
 
- From: "vic plichota" <atsvap@xxxxxxxxxxx>
 
- Date: Fri, 19 Feb 1999 19:50:49 -0500
 
Comments, folks?
nFORTH = nanoFORTH:  a viable stack-computer with 4-bit opcodes
-- perhaps the irreducible ultimate in "software DeMorgan-ization"?
v2.3  Feb 19, 1999  (this doc is verrry rough and crude)
(c) vic plichota, original concept by Myron Plichota Dec '98, polished over the MISC list.
OPCODE SUMMARY:
add	.equ	0
nand	.equ	1
xor	.equ	2
ashr	.equ	3
fetch	.equ	4
store	.equ	5
lit	.equ	6
dup	.equ	7
swap	.equ	8
drop	.equ	9
tor	.equ	10
rfrom	.equ	11
enter	.equ	12
exit	.equ	13
zjmp	.equ	14
iptor	.equ	15
(an almost) FORMAL DESCRIPTION:
GLOSSARY:
AKA:  Also Known As
cell-size:  the nFORTH machine-implementation's native integer format
iff:  "if and only if"
ILK:  'immediate' in-line constant, with the same number of bits as the cell-size
IP:  the Instruction Pointer, AKA 'program counter'
N:  Next-from-top entry on parameter-stack
R:  Top entry on return-stack
T:  Top entry on parameter-stack
(. . .):  parameter-stack diagram
<. . .>:  return-stack diagram
|:  pipe char used to indicate an "either-or" choice
0:
add	AKA  '+', "plus"
(n1, n2 -- n3)
1:
nand	AKA  '&~'
(x1, x2 -- x3)
2:
xor	AKA  '><'
(x1, x2 -- x3)
3:
ashr	AKA  '2/', "two-div", "two-slash", '>>';  arithmetic shift-right
(n1 -- n2)
4:
fetch	AKA  '@', "peek"
(addr --- x)
5:
store	AKA  '!', "poke"
(x, addr --  )
6:
lit	;  "push literal";  in-line immediate constant --> T
(  -- ILK)
7:
dup	; duplicate T
(x -- x, x)
8:
swap	; exchange T with N
(x, y -- y, x)
9:
drop	; pop and discard T
(x --  )
10:
tor	AKA  '>R', "to-R";  transfer T to R
(x --  )
<  -- x>
11:
rfrom	AKA  'R>', "R-from";  transfer R to T
(  -- x)
<x --  >
12:
enter	AKA  ':', "docol", "nest", "call";  enter procedure
<  -- IP>,  ILK-->IP
13:
exit	AKA  ';', "semis", "return";  un-nest procedure level
<x --  >,  x-->IP
14:
zjmp	; jump to ILK iff T=0
(x --  ),  T=N:  ILK-->IP  |  T<>0:  IP+native cell-size -->IP
15:
iptor	AKA 'begin'  ; push IP (next instruction fetch addr) to R
<  -- IP>
DERIVED OPERATIONS (some examples)
_ddrop:   drop drop exit
_rot:   tor swap rfrom swap exit
_over:   tor dup rfrom swap exit
_not:   dup nand exit
_and:  nand dup nand exit
_or:   dup nand swap dup nand nand exit
_negate:   dup nand lit 1 add exit
_subtract:  dup nand lit 1 add add exit
_nondestructive-subtract:   enter _over enter _over enter _subtract exit
_shl:   dup add exit		;  AKA  '2*', "two-star", '<<';  shift-left