A minor update. The source for my Forth's # used to be this:
Code:
HEX
: # ( D1 -- D2 )
BASE @ UD/MOD ROT
INLINE
0 ,X LDA, 0A # CMP, CS IF,
6 # ADC,
THEN,
30 # ADC, 0 ,X STA,
END-INLINE
HOLD ;
It is now this:
Code:
: # ( D1 -- D2 )
BASE @ UD/MOD ROT
>ASSEM
0 ,X LDA #10 # CMP
CS IF 6 # ADC THEN
#48 # ADC 0 ,X STA
LABEL HOLD.BODY
SEC
' HLD >BODY C@ # LDY
DEX DEX
UP )Y LDA 1 # SBC UP )Y STA
0 ,X STA INY
UP )Y LDA 0 # SBC UP )Y STA
1 ,X STA
LABEL C!.BODY
2 ,X LDA 0 X) STA
POPTWO JMP END-CODE
HOLD and C! have no bodies. Their code fields point into the low level portion of # and SIGN is now a primitive.
Code:
CODE HOLD ( C -- )
HOLD.BODY LATEST NAME> !
END-CODE
CODE C! ( C ADR -- )
C!.BODY LATEST NAME> !
END-CODE
CODE SIGN ( N -- )
1 ,X ASL ASCII - # LDA
0 ,X STA
' HOLD @ CS BRAN
POP JMP END-CODE
Although # is much larger, less memory is used for these words than if # , HOLD and SIGN were high level. A savings of a few bytes and a speed up from mixing low level code in a high level word.