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.s | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'jefs.s') 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 -- cgit v1.2.3