From: Jonas Hvid Date: Mon, 9 Dec 2019 17:09:38 +0000 (+0100) Subject: Implement some arithmetic words X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=02f53b20b4f7244a84a442bbae10eb8401abcfc5;p=rrq%2Fjonasforth.git Implement some arithmetic words --- diff --git a/main.asm b/main.asm index 67e9a7b..d2cd54d 100644 --- a/main.asm +++ b/main.asm @@ -431,6 +431,17 @@ forth_asm MINUS, '-' push rbx next +;; Given two integers a and b on the stack, pushes the quotient and remainder of +;; division of a by b. +forth_asm TIMESMOD, '/MOD' + pop rbx ; b + pop rax ; a + mov rdx, 0 + div rbx + push rax ; a / b + push rdx ; a % b + next + ;; Get the location of the STATE variable. It can be set with '!' and read with ;; '@'. forth STATE, 'STATE' diff --git a/sys.f b/sys.f index bc9dae9..23fed87 100644 --- a/sys.f +++ b/sys.f @@ -9,3 +9,7 @@ EXIT [ [ S" [" FIND >CFA , ] EXIT [ IMMEDIATE + +: / /MOD DROP ; +: MOD /MOD SWAP DROP ; +: NEG 0 SWAP - ;