figForth - CODE Definitions
Some parts of this page/site are currently incomplete & will be updated asap
Other parts will change continually so use “Refresh” in your browser !!
There is extensive use of “Tooltips” text to support learning which do not seem to render on a Smartphone. This site is best viewed via a computer’s HD monitor
In Forth, words defined in machine code are known as Code Definitions or primatives
The Word DUP will be discussed…
DUP n --- n n L0
Duplicate the value on the stack
NFA: 002705 83 DB 83H
002706 4455 DB "DU"
002708 D0 DB 'P'+80H
LFA: 002709 EF26 DW DSWAP-8
CFA: 00270B 0D27 DUP: DW $+2
PFA+0: 00270D E1 POP HL
PFA+1: 00270E E5 PUSH HL
PFA+2: 00270F C3 E1 20 JP HPUSH
Fig#1 Forth Primative DUP
The Meaning of the Dictionary Fields:
So the first thing to notice is that the CFA is pointing towards the PFA which contains the assember code
This is CFA Rule#1 - that the CFA ALWAYS points towards executable machine code and in the case of Code Definitions, the Address Threader will jump to the PFA (“PFA+0”) and start executing the code it finds there…
So in this case: 16-bit value n is already on the stack (Parameter Stack = the Microprocessor’s Stack)
So the first thing the code at PFA+0 does is POP the 16-bit value (n) off of the stack into the register pair “HL”
Then it PUSHes a copy of HL back onto the stack, leaving n still in HL
Finally, it needs to PUSH HL again to create a duplicate of n on the stack, which will then contain two n items…
It does a jump to the address threader entry point HPUSH by executing a JP HPUSH, given that HPUSH’s 1st instruction is PUSH HL… Job done !!
0020E0 D5 WHPUSH: PUSH DE
0020E1 E5 HPUSH: PUSH HL
0020E2 CD AE 02 NEXT: CALL PAUSE
0020E5 0A NEXT2: LD A,(BC)
0020E6 03 INC BC
0020E7 6F LD L,A
0020E8 0A LD A,(BC) ; Preserve BC !!
0020E9 03 INC BC
0020EA 67 LD H,A
0020EB ED17 NEXT1: LD DE,(HL)
0020ED 23 INC HL
0020EE EB EX DE,HL
0020EF E9 JP (HL)
Fig#2 The Inner Interpreter (“Address Threader”) NEXT