From: Jonas Hvid Date: Sat, 23 Nov 2019 16:05:32 +0000 (+0100) Subject: Implement 0BRANCH X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=3e2708b7e8434cc0678c8ee0c315166704c8f31a;p=rrq%2Fjonasforth.git Implement 0BRANCH --- diff --git a/main.asm b/main.asm index e5444b8..af84a66 100644 --- a/main.asm +++ b/main.asm @@ -59,6 +59,23 @@ LIT: push rax next +;; 0BRANCH is the fundamental mechanism for branching. If the top of the stack +;; is zero, we jump by the given offset. 0BRANCH is given the offset as an +;; integer after the word. +ZBRANCH: + dq .start +.start: + ;; Compare top of stack to see if we should branch + pop rax + cmp rax, 0 + jnz .dont_branch +.do_branch: + add rsi, [rsi] ; [RSI], which is the next word, contains the offset; we add this to the instruction pointer. + next ; Then, we can just continue execution as normal +.dont_branch: + add rsi, 8 ; We need to skip over the next word, which contains the offset. + next + ;; Expects a character on the stack and prints it to standard output. EMIT: dq .start