forth: add +-*/

This commit is contained in:
Virgil Dupras 2020-03-07 19:42:07 -05:00
parent ad2aca4620
commit 580214426a
3 changed files with 55 additions and 1 deletions

View File

@ -248,3 +248,53 @@ FETCH:
call intoHL
push hl
jp exit
; ( a b -- c ) A + B
PLUS:
.db "+"
.fill 7
.dw FETCH
.dw nativeWord
pop hl
pop de
add hl, de
push hl
jp exit
; ( a b -- c ) A - B
MINUS:
.db "-"
.fill 7
.dw PLUS
.dw nativeWord
pop de ; B
pop hl ; A
or a ; reset carry
sbc hl, de
push hl
jp exit
; ( a b -- c ) A * B
MULT:
.db "*"
.fill 7
.dw MINUS
.dw nativeWord
pop de
pop bc
call multDEBC
push hl
jp exit
; ( a b -- c ) A / B
DIV:
.db "/"
.fill 7
.dw MULT
.dw nativeWord
pop de
pop hl
call divide
push bc
jp exit

View File

@ -6,6 +6,10 @@ Stack notation: "<stack before> -- <stack after>". Rightmost is top of stack
. n -- Print n in its decimal form
@ a -- n Set n to value at address a
! n a -- Store n in address a
+ a b -- c a + b -> c
- a b -- c a - b -> c
* a b -- c a * b -> c
/ a b -- c a / b -> c
CREATE x -- Create cell named x
EMIT c -- Spit char c to stdout
EXECUTE a -- Execute word at addr a

View File

@ -48,7 +48,7 @@ CHKEND:
forthMain:
ld (INITIAL_SP), sp
ld hl, FETCH ; last entry in hardcoded dict
ld hl, DIV ; last entry in hardcoded dict
ld (CURRENT), hl
ld hl, FORTH_RAMEND
ld (HERE), hl