forth: add words "2DUP", "2SWAP", "2OVER"

This commit is contained in:
Virgil Dupras 2020-03-11 21:58:16 -04:00
parent d8542f7cf7
commit 80f63cd185
2 changed files with 54 additions and 4 deletions

View File

@ -421,10 +421,26 @@ SWAP:
push hl push hl
jp exit jp exit
; ( a b c d -- c d a b )
.db "2SWAP"
.fill 3
.dw SWAP
SWAP2:
.dw nativeWord
pop de ; D
pop hl ; C
pop bc ; B
ex (sp), hl ; A in HL
push de ; D
push hl ; A
push bc ; B
jp exit
; ( a -- a a ) ; ( a -- a a )
.db "DUP" .db "DUP"
.fill 5 .fill 5
.dw SWAP .dw SWAP2
DUP: DUP:
.dw nativeWord .dw nativeWord
pop hl pop hl
@ -432,10 +448,24 @@ DUP:
push hl push hl
jp exit jp exit
; ( a b -- a b a b )
.db "2DUP"
.fill 4
.dw DUP
DUP2:
.dw nativeWord
pop hl ; B
pop de ; A
push de
push hl
push de
push hl
jp exit
; ( a b -- a b a ) ; ( a b -- a b a )
.db "OVER" .db "OVER"
.fill 4 .fill 4
.dw DUP .dw DUP2
OVER: OVER:
.dw nativeWord .dw nativeWord
pop hl ; B pop hl ; B
@ -445,10 +475,28 @@ OVER:
push de push de
jp exit jp exit
; ( a b c d -- a b c d a b )
.db "2OVER"
.fill 3
.dw OVER
OVER2:
.dw nativeWord
pop hl ; D
pop de ; C
pop bc ; B
pop iy ; A
push iy ; A
push bc ; B
push de ; C
push hl ; D
push iy ; A
push bc ; B
jp exit
; ( a b -- c ) A + B ; ( a b -- c ) A + B
.db "+" .db "+"
.fill 7 .fill 7
.dw OVER .dw OVER2
PLUS: PLUS:
.dw nativeWord .dw nativeWord
pop hl pop hl
@ -712,4 +760,3 @@ LATEST:
.dw NUMBER .dw NUMBER
.dw 1 .dw 1
.dw EQ .dw EQ
.dw EXIT

View File

@ -51,6 +51,9 @@ THEN -- Does nothing. Serves as a branching merker for IF
DUP a -- a a DUP a -- a a
OVER a b -- a b a OVER a b -- a b a
SWAP a b -- b a SWAP a b -- b a
2DUP a b -- a b a b
2OVER a b c d -- a b c d a b
2SWAP a b c d -- c d a b
*** Memory *** *** Memory ***
@ a -- n Set n to value at address a @ a -- n Set n to value at address a