aforth

FORTH for Linux x86-64, written in assembly.
git clone git://henryandlizzy.uk/aforth
Log | Files | Refs | README

commit 830e23b805e3e2aa989d3b3f37251de72facd554
parent 2df2830edd48fcc92a9eb19163300bb51f6845f0
Author: Henry Wilson <m3henry@googlemail.com>
Date:   Fri, 16 Jun 2017 12:45:38 +0100

comparisons, negate

Diffstat:
Mcompile | 1+
Mmain.s | 31++++++++++++++++++++++++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/compile b/compile @@ -1,3 +1,4 @@ #! /bin/bash gcc -c main.s && ld main.o && rm main.o && ./a.out +echo $? diff --git a/main.s b/main.s @@ -39,6 +39,10 @@ quit: forthword string "Hello, World!" .quad print .quad cr + const -10 + .quad negate + const 10 + .quad equal .quad halt flag: forthword @@ -222,7 +226,7 @@ top: codeword true: codeword _dup - mov $-1, TOS + movq $-1, TOS jmp next false: codeword @@ -272,6 +276,31 @@ dec: codeword dec TOS jmp next +negate: codeword + neg TOS + jmp next + +# Comparison + +.macro compare op + codeword + cmp TOS, (SP) + \op truecmp + movq $0, (SP) + jmp _drop +.endm + +truecmp: + movq $-1, (SP) + jmp _drop + +equal: compare je +nequal: compare jne +greater: compare jg +less: compare jl +gequal: compare jge +lequal: compare jle + # Kernel exit: codeword