From f05a9a424e2d5cfc15f55cee82f503d7b4c1e5a9 Mon Sep 17 00:00:00 2001 From: Jonas Hvid Date: Tue, 10 Dec 2019 18:21:41 +0100 Subject: [PATCH 1/1] Reimplement HELLO in Forth This implementation is a bit awkward right now, but we should be able to clean it up later. --- main.asm | 11 ----------- sys.f | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/main.asm b/main.asm index cb2e0d5..1a41bb9 100644 --- a/main.asm +++ b/main.asm @@ -235,16 +235,6 @@ forth_asm TERMINATE, 'TERMINATE' mov rdi, 0 syscall -forth HELLO, 'HELLO' - dq LIT, 'H', EMIT - dq LIT, 'e', EMIT - dq LIT, 'l', EMIT - dq LIT, 'l', EMIT - dq LIT, 'o', EMIT - dq LIT, '!', EMIT - dq NEWLINE - dq EXIT - ;; Duplicate a pair of elements. forth_asm PAIRDUP, '2DUP' pop rbx @@ -592,7 +582,6 @@ forth_asm EQL, '=' next forth MAIN, 'MAIN' - dq HELLO dq INTERPRET dq BRANCH, -8 * 2 dq TERMINATE diff --git a/sys.f b/sys.f index 0996352..604d87a 100644 --- a/sys.f +++ b/sys.f @@ -55,6 +55,29 @@ EXIT [ DROP SWAP DROP SWAP DROP ; +: C, + HERE @ C! + HERE @ 1 + + HERE ! ; + +: OVER + SWAP DUP ROT ; + +: STORE-STRING + BEGIN + OVER C@ C, + SWAP 1 + SWAP + 1 - DUP 0 = UNTIL + DROP DROP ; + +S" HELLO-ADDR" CREATE +S" Hello!" DUP ROT +STORE-STRING +: HELLO + ' HELLO-ADDR LIT [ , ] TELL NEWLINE ; + +HELLO + S" 10 FIB = " TELL 10 FIB .U S" (Expected: 59)" TELL NEWLINE -- 2.39.2