forth: add words "AND", "OR", "XOR"

This commit is contained in:
Virgil Dupras 2020-03-21 14:47:38 -04:00
parent c1ece95089
commit b47a3ee234
2 changed files with 60 additions and 2 deletions

View File

@ -120,7 +120,7 @@ CURRENT -- a Set a to wordref of last added entry.
HERE -- a Push HERE's address
H -- a HERE @
*** Arithmetic ***
*** Arithmetic / Bits ***
+ a b -- c a + b -> c
- a b -- c a - b -> c
@ -129,6 +129,9 @@ H -- a HERE @
/ a b -- c a / b -> c
MOD a b -- c a % b -> c
/MOD a b -- r q r:remainder q:quotient
AND a b -- c a & b -> c
OR a b -- c a | b -> c
XOR a b -- c a ^ b -> c
*** Logic ***
= n1 n2 -- f Push true if n1 == n2

View File

@ -1618,10 +1618,65 @@ DIVMOD:
push bc
jp next
.db "AND"
.fill 4
.dw DIVMOD
.db 0
AND:
.dw nativeWord
pop hl
pop de
call chkPS
ld a, e
and l
ld l, a
ld a, d
and h
ld h, a
push hl
jp next
.db "OR"
.fill 5
.dw AND
.db 0
OR:
.dw nativeWord
pop hl
pop de
call chkPS
ld a, e
or l
ld l, a
ld a, d
or h
ld h, a
push hl
jp next
.db "XOR"
.fill 4
.dw OR
.db 0
XOR:
.dw nativeWord
pop hl
pop de
call chkPS
ld a, e
xor l
ld l, a
ld a, d
xor h
ld h, a
push hl
jp next
; ( a1 a2 -- b )
.db "SCMP"
.fill 3
.dw DIVMOD
.dw XOR
.db 0
SCMP:
.dw nativeWord