diff options
| author | kitty <nepeta@canaglie.net> | 2026-03-19 18:52:59 +1100 |
|---|---|---|
| committer | kitty <nepeta@canaglie.net> | 2026-03-19 18:52:59 +1100 |
| commit | ae2bb07e11ce6582cc9c7d45d1b8137c355e9db7 (patch) | |
| tree | 7d97c829a1b6e50737119996a3545f2f9293a91c | |
| parent | e8d44270cde4c9e3149cde0ab9ae6bf58cd05578 (diff) | |
math stuff
| -rw-r--r-- | readme.md | 39 | ||||
| -rw-r--r-- | sanctuary.fs | 4 | ||||
| -rw-r--r-- | sanctuary.s | 64 |
3 files changed, 98 insertions, 9 deletions
@@ -1,7 +1,6 @@ # sanctuary (working title) -sanctuary is a 64-bit subroutine threaded forth system -for amd64 linux systems. +sanctuary is a 64-bit subroutine threaded forth for amd64 linux systems. ## stack effect notation @@ -26,6 +25,26 @@ create a dictionary header for a word named the provided string. this word does not set the code field. this word returns an incompleted xt and does not update latest. +### `* ( u1 u2 -- u)` +multiply u1 and u2. + +### `*/mod ( n1 n2 n3 -- n4 n5 )` +multiply n1 and n2, divide the result by n3. +remainder is in n3, result is in n4 + +### `+ ( u1 u2 -- u )` +add u2 to u1. + +### `- ( u1 u2 -- u )` +subtract u2 from u1. + +### `-rot ( u1 u2 u3 -- u3 u1 u2 )` +rotate the three topmost values on the stack so that the topmost value +is moved to the third highest. + +### `/mod ( u1 u2 -- u3 u4 )` +divide u1 by u2. result is in u4, remainder is in u3. + ### `[ ( -- ) IMMEDIATE` set the system to interpret mode. @@ -38,10 +57,6 @@ start compilation of the word 'name'. ### `; ( -- ) IMMEDIATE` end compilation of the currently compiling word. -### `-rot ( u1 u2 u3 -- u3 u1 u2 )` -rotate the three topmost values on the stack so that the topmost value -is moved to the third highest. - ### `>body ( xt -- a )` yield the code field of xt. @@ -58,6 +73,9 @@ remove the two topmost values from the stack. ### `2dup ( u1 u2 -- u1 u2 u1 u2 )` duplicate the two topmost values on the stack. +### `and ( u1 u2 -- u )` +perform bitwise AND on u1 and u2. + ### `brk@ ( -- a )` yields current program break. @@ -103,6 +121,9 @@ true if xt is marked immediate, false otherwise. interprets the contents of the terminal input buffer until it runs out. +### `invert ( u -- u')` +invert all bytes in u. + ### `latest ( -- a )` a variable containing the execution token of the most recently created word. @@ -115,6 +136,9 @@ convert given string into a number along with a flag. if parsing a number fails then 0 (false) is returned and no number is provided. +### `or ( u1 u2 -- u )` +perform bitwise OR on u1 and u2. + ### `parse ( "name<c>" c -- a u )` parse one word from the input buffer, separated by a newline or the character c, @@ -174,6 +198,9 @@ write u characters at a to output. ### `over ( u1 u2 -- u1 u2 u1 )` copy the second-highest value on the stack and move it to the top of the stack. +### `xor ( u1 u2 -- u )` +perform bitwise XOR on u1 and u2. + ## dictionary format note that the string length of one byte limits a word's name to 255 characters. diff --git a/sanctuary.fs b/sanctuary.fs index 43dc7bb..8b13789 100644 --- a/sanctuary.fs +++ b/sanctuary.fs @@ -1,3 +1 @@ -: .s2 1 2 3 [ 7 ] literal .s ; -4 5 6 .s2 -bye + diff --git a/sanctuary.s b/sanctuary.s index f9fc5f0..44cd4af 100644 --- a/sanctuary.s +++ b/sanctuary.s @@ -449,6 +449,7 @@ defcode "(header)", brac_header, 0 pspush r12 ret +; fix to follow ans: yielding colon-sys defcode ":", colon, 0 call parse_name ; todo check zero @@ -459,6 +460,8 @@ defcode ":", colon, 0 mov qword [state], COMPILING ret +; fix to follow ans: reading from colon-sys +; this will not work with :noname or i think does>. defcode ";", semicolon, immediate_mask mov r12, [latest] add r12, 8 @@ -659,6 +662,67 @@ defcode "rdrop", rdrop, 0 ; }}} ; math + comparison {{{ +; i believe some of these could be improved by direct accesses to [r15] +defcode "+", plus, 0 + pspop r11 + pspop r12 + add r11, r12 + pspush r11 + ret + +defcode "-", minus, 0 + pspop r11 + pspop r12 + sub r12, r11 + pspush r12 + ret + +defcode "*", _times, 0 + pspop r11 + pspop r12 + imul r11, r12 + pspush r11 + ret + +defcode "/mod", divmod, 0 + xor rdx, rdx + pspop r11 + pspop rax + idiv r11 + pspush rdx + pspush rax + ret + +defcode "and", _and, 0 + pspop r11 + and [r14], r11 + ret + +defcode "or", _or, 0 + pspop r11 + or [r14], r11 + ret + +defcode "xor", _xor, 0 + pspop r11 + xor [r14], r11 + ret + +defcode "invert", invert, 0 + not qword [r14] + ret + +defcode "*/mod", starslashmod, 0 + pspop r15 ; n3 + pspop r13 ; n2 + pspop rax ; n1 + + imul r13 + idiv r15 + + pspush rdx + pspush rax + ret ; }}} ; TEMPORARY WONKY DEBUGGING FUNCTIONS {{{ |
