From 11ab7360e32aebf5dfc5a1331ebe44b0ceff6354 Mon Sep 17 00:00:00 2001 From: kitty Date: Mon, 16 Feb 2026 23:33:25 +1100 Subject: port some comparison n logic words from jf --- jefs.fs | 1 - jefs.s | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 2 ++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/jefs.fs b/jefs.fs index 8e56fd2..c37067d 100644 --- a/jefs.fs +++ b/jefs.fs @@ -13,7 +13,6 @@ : [compile] parse find drop >cfa compile, ; immediate : ' parse find drop >cfa [compile] lit ; immediate \ note: no error handling (yet) : constant create [compile] lit 195 ( ret ) c, ; -65 constant TESTING : begin here @ ; immediate : again branch here @ 4 + - d, ; immediate \ add 4 to get to beginning of the next instruction diff --git a/jefs.s b/jefs.s index 4c3f291..f5c2858 100644 --- a/jefs.s +++ b/jefs.s @@ -84,6 +84,7 @@ defword "bye", bye, 0 syscall ret ; will not be reached +; mem access {{{ defword "@", fetch, 0 pspop r11 mov r12, qword [r11] @@ -186,6 +187,7 @@ defword "cmove,", _cmove_comma, 0 ; ( c-addr u -- ) add r12, r9 mov qword [here], r12 ret +; }}} ; note: this puts the _address it itself pushes_ on the stack ; maybe this is not the correct approach? @@ -579,6 +581,7 @@ defword "syscall3", syscall3, 0 ; ( rdx rsi rdi id -- rax ) pspush rax ret +; stack {{{ ; these stack wrangling words are dreadfully inefficient right now ; i will come back and make these less terrible later defword "dup", dup, 0 @@ -637,7 +640,9 @@ defword "2drop", twodrop, 0 defword "rdrop", rdrop, 0 pop r11 ret +; }}} +; math {{{ defword "+", plus, 0 pspop r11 pspop r12 @@ -668,6 +673,84 @@ defword "/mod", divmod, 0 pspush rax ret +defword "and", _and, 0 + pspop r11 + and [r14], r11 + ret + +defword "or", _or, 0 + pspop r11 + or [r14], r11 + ret + +defword "xor", _xor, 0 + pspop r11 + xor [r14], r11 + ret + +defword "invert", invert, 0 + not qword [r14] + ret +; }}} + +; comparison {{{ +; the 'neg' converts the sete 0x1 into 0xffff (-1) which is this forth's +; truth value +defword "=", equals, 0 + pspop r11 + pspop r12 + cmp r11, r12 + sete r13b + movzx r11, r13b + neg r11 + ret + +defword "<>", less_greater, 0 + pspop r11 + pspop r12 + cmp r11, r12 + setne r13b + movzx r11, r13b + neg r11 + ret + +defword "<", less, 0 + pspop r11 + pspop r12 + cmp r11, r12 + setl r13b + movzx r11, r13b + neg r11 + ret + +defword ">", greater, 0 + pspop r11 + pspop r12 + cmp r11, r12 + setg r13b + movzx r11, r13b + neg r11 + ret + +defword "<=", lesseq, 0 + pspop r11 + pspop r12 + cmp r11, r12 + setle r13b + movzx r11, r13b + neg r11 + ret + +defword ">=", greatereq, 0 + pspop r11 + pspop r12 + cmp r11, r12 + setge r13b + movzx r11, r13b + neg r11 + ret +; }}} + defword "[", lbrac, immediate_mask mov qword [state], interpreting ret diff --git a/readme.md b/readme.md index 58c8dc7..38a17ab 100644 --- a/readme.md +++ b/readme.md @@ -40,6 +40,8 @@ so a wonky but hopefully not too slow solution is to compile ### Some Links - starting forth part 1: http://www.bradrodriguez.com/papers/moving1.htm +- jonesforth, public domain forth tutorial implementation which was significantly cribbed from and studied: http://git.annexia.org/?p=jonesforth.git;a=tree +- jonesforth nasm port: http://ratfactor.com/repos/nasmjf/ ## silly little plans -- cgit v1.2.3