From 839d7097e749819cfc57eef11e7068e8cee697ec Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 16 Mar 2020 22:36:29 -0400 Subject: [PATCH] forth: add words "MOD" and "/MOD" --- apps/forth/core.fs | 2 ++ apps/forth/dict.asm | 11 ++++++----- apps/forth/dictionary.txt | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/forth/core.fs b/apps/forth/core.fs index 06189d5..a021a8e 100644 --- a/apps/forth/core.fs +++ b/apps/forth/core.fs @@ -47,3 +47,5 @@ : = CMP NOT ; : < CMP 0 1 - = ; : > CMP 1 = ; +: / /MOD SWAP DROP ; +: MOD /MOD DROP ; diff --git a/apps/forth/dict.asm b/apps/forth/dict.asm index 6f72370..3ac6dbc 100644 --- a/apps/forth/dict.asm +++ b/apps/forth/dict.asm @@ -734,23 +734,24 @@ MULT: push hl jp next -; ( a b -- c ) A / B - .db "/" - .fill 6 + + .db "/MOD" + .fill 3 .dw MULT .db 0 -DIV: +DIVMOD: .dw nativeWord pop de pop hl call divide + push hl push bc jp next ; ( a1 a2 -- b ) .db "SCMP" .fill 3 - .dw DIV + .dw DIVMOD .db 0 SCMP: .dw nativeWord diff --git a/apps/forth/dictionary.txt b/apps/forth/dictionary.txt index a4a6a1d..a83e812 100644 --- a/apps/forth/dictionary.txt +++ b/apps/forth/dictionary.txt @@ -121,6 +121,8 @@ H -- a HERE @ -^ a b -- c b - a -> c * a b -- c a * b -> c / a b -- c a / b -> c +MOD a b -- c a % b -> c +/MOD a b -- r q r:remainder q:quotient *** Logic *** = n1 n2 -- f Push true if n1 == n2