From 02f53b20b4f7244a84a442bbae10eb8401abcfc5 Mon Sep 17 00:00:00 2001 From: Jonas Hvid Date: Mon, 9 Dec 2019 18:09:38 +0100 Subject: [PATCH] Implement some arithmetic words --- main.asm | 11 +++++++++++ sys.f | 4 ++++ 2 files changed, 15 insertions(+) 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 - ; -- 2.39.2