forth: add words "MOD" and "/MOD"

This commit is contained in:
Virgil Dupras 2020-03-16 22:36:29 -04:00
parent 5d5517ac44
commit 839d7097e7
3 changed files with 10 additions and 5 deletions

View File

@ -47,3 +47,5 @@
: = CMP NOT ;
: < CMP 0 1 - = ;
: > CMP 1 = ;
: / /MOD SWAP DROP ;
: MOD /MOD DROP ;

View File

@ -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

View File

@ -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