From b47a3ee2343e212b578ab9a1e2a8728cc7c8c350 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 21 Mar 2020 14:47:38 -0400 Subject: [PATCH] forth: add words "AND", "OR", "XOR" --- forth/dictionary.txt | 5 +++- forth/forth.asm | 57 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/forth/dictionary.txt b/forth/dictionary.txt index cad1743..9f32c4e 100644 --- a/forth/dictionary.txt +++ b/forth/dictionary.txt @@ -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 diff --git a/forth/forth.asm b/forth/forth.asm index 202fb80..41f015f 100644 --- a/forth/forth.asm +++ b/forth/forth.asm @@ -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