mirror of
https://github.com/hsoft/collapseos.git
synced 2025-01-13 01:58:05 +11:00
forth: add +-*/
This commit is contained in:
parent
ad2aca4620
commit
580214426a
@ -248,3 +248,53 @@ FETCH:
|
|||||||
call intoHL
|
call intoHL
|
||||||
push hl
|
push hl
|
||||||
jp exit
|
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
|
||||||
|
|
||||||
|
@ -6,6 +6,10 @@ Stack notation: "<stack before> -- <stack after>". Rightmost is top of stack
|
|||||||
. n -- Print n in its decimal form
|
. n -- Print n in its decimal form
|
||||||
@ a -- n Set n to value at address a
|
@ a -- n Set n to value at address a
|
||||||
! n a -- Store n in 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
|
CREATE x -- Create cell named x
|
||||||
EMIT c -- Spit char c to stdout
|
EMIT c -- Spit char c to stdout
|
||||||
EXECUTE a -- Execute word at addr a
|
EXECUTE a -- Execute word at addr a
|
||||||
|
@ -48,7 +48,7 @@ CHKEND:
|
|||||||
|
|
||||||
forthMain:
|
forthMain:
|
||||||
ld (INITIAL_SP), sp
|
ld (INITIAL_SP), sp
|
||||||
ld hl, FETCH ; last entry in hardcoded dict
|
ld hl, DIV ; last entry in hardcoded dict
|
||||||
ld (CURRENT), hl
|
ld (CURRENT), hl
|
||||||
ld hl, FORTH_RAMEND
|
ld hl, FORTH_RAMEND
|
||||||
ld (HERE), hl
|
ld (HERE), hl
|
||||||
|
Loading…
Reference in New Issue
Block a user