From: Jonas Hvid Date: Tue, 10 Dec 2019 15:58:14 +0000 (+0100) Subject: Implement looping words and add fibonacci example X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=3e21454c3e1e006a38d2a05d856e4651d099b668;p=rrq%2Fjonasforth.git Implement looping words and add fibonacci example --- diff --git a/main.asm b/main.asm index 086d1dc..cb2e0d5 100644 --- a/main.asm +++ b/main.asm @@ -563,6 +563,34 @@ forth_asm TICK, "'" push rax next +forth_asm ROT, 'ROT' + pop rax + pop rbx + pop rdx + push rax + push rdx + push rbx + next + +forth_asm PICK, 'PICK' + pop rax + lea rax, [rsp + 8 * rax] + mov rax, [rax] + push rax + next + +forth_asm EQL, '=' + pop rax + pop rbx + cmp rax, rbx + je .eq +.noteq: + push 0 + next +.eq: + push 1 + next + forth MAIN, 'MAIN' dq HELLO dq INTERPRET diff --git a/sys.f b/sys.f index cab2ab7..0996352 100644 --- a/sys.f +++ b/sys.f @@ -33,3 +33,29 @@ EXIT [ SWAP DUP HERE @ SWAP - SWAP ! ; +: BEGIN IMMEDIATE + HERE @ +; + +: UNTIL IMMEDIATE + ' 0BRANCH , + HERE @ - , +; + +: FIB + 0 1 + 0 + BEGIN + ROT + DUP ROT + + ROT ROT + + 1 + + DUP 4 PICK = UNTIL + DROP SWAP DROP SWAP DROP +; + +S" 10 FIB = " TELL +10 FIB .U +S" (Expected: 59)" TELL NEWLINE +