diff options
| author | kitty <nepeta@canaglie.net> | 2026-03-16 00:23:02 +1100 |
|---|---|---|
| committer | kitty <nepeta@canaglie.net> | 2026-03-16 00:23:02 +1100 |
| commit | 2a806c6fbc434d4cdd51d5e64019775c40c34475 (patch) | |
| tree | 7a9fcfbadd3e5d56c892185958ffafdb77003734 | |
| parent | 85199c06b8e104dfed0366389e6b95a7757d0510 (diff) | |
remove TOS register, move SP to r15, `type`
TOS efficiency gain is negligible and it complicates the implementation.
i'm going to make a stack dump word in a bit so now is a good time
to get rid of this for simplicity's sake.
i also took this opportunity to move it to r15 so the reserved register
is numerically the highest.
| -rw-r--r-- | readme.md | 6 | ||||
| -rw-r--r-- | sanctuary.s | 58 |
2 files changed, 38 insertions, 26 deletions
@@ -72,6 +72,9 @@ if -1 (true), the system is in compiling mode. ### `tib ( -- a )` a variable containing the address of the current input buffer. +### `type ( u a -- )` +write u characters at a to output. + ## dictionary format note that the string length of one byte limits a word's name to 255 characters. @@ -86,5 +89,4 @@ note that the string length of one byte limits a word's name to 255 characters. ## reserved registers -the registers `r14` and `r15` are reserved for the parameter stack -and the top of stack respectively. +the register `r15` is reserved for the parameter stack pointer. diff --git a/sanctuary.s b/sanctuary.s index 235f384..c5eac72 100644 --- a/sanctuary.s +++ b/sanctuary.s @@ -3,19 +3,13 @@ ; macros {{{ ; TODO: error handling (once i add that) %macro pspush 1 - lea r14, [r14-8] - mov qword [r14], r15 - mov r15, %1 + lea r15, [r15-8] + mov qword [r15], %1 %endmacro %macro pspop 1 - mov %1, r15 - mov r15, qword [r14] - lea r14, [r14+8] -%endmacro - -%macro psdrop 0 - lea r14, [r14+8] + mov %1, qword [r15] + lea r15, [r15+8] %endmacro %define s_latest 0 @@ -47,8 +41,9 @@ ; }}} %assign INTERPRET 0x0 -%assign COMPILING (~0x1) +%assign COMPILING (~0x0) +%assign __NR_write 1 %assign __NR_mprotect 10 %assign __NR_brk 12 %assign __NR_exit 60 @@ -60,15 +55,21 @@ wstk: resq 1 section .text global _start _start: - lea r14, [wstk + 8] + lea r15, [wstk] call brk@ - mov qword [dp], r15 - mov qword [dp0], r15 - mov r15, 0x9c400 + pspop r11 + mov qword [dp], r11 + mov qword [dp0], r11 + mov r11, 0x9c400 + pspush r11 call grow + call parse_name + call type call bye +teststr: db "TESTING" + defcode "brk@", brk@, 0 xor rdi, rdi mov rax, __NR_brk @@ -95,7 +96,8 @@ defcode "executable", executable, 0 ret defcode "here", here, 0 - pspush qword [dp] + mov r11, qword [dp] + pspush r11 ret defcode "bye", bye, 0 @@ -141,7 +143,6 @@ defcode "parse-name", parse_name, 0 cmp al, 0x0a je .wordloop_e - ; is there a better way of checking before? cmp rsi, r10 jge .wordloop_e inc r11 @@ -166,6 +167,7 @@ defcode "parse-name", parse_name, 0 ; al: char being parsed ; r10: end of input buffer defcode "parse", parse, 0 + pspop rbx mov rsi, qword [to_in] mov r10, qword [tib] add rsi, r10 @@ -176,7 +178,7 @@ defcode "parse", parse, 0 cmp rsi, r10 jge .empty lodsb - cmp al, r15b + cmp al, bl je .wsloop cmp al, 0x0a je .wsloop @@ -188,12 +190,11 @@ defcode "parse", parse, 0 push rsi ; will become `a` inc rsi .wordloop: - cmp al, r15b + cmp al, bl je .wordloop_e cmp al, 0x0a je .wordloop_e - ; is there a better way of checking before? cmp rsi, r10 jge .wordloop_e inc r11 @@ -204,23 +205,32 @@ defcode "parse", parse, 0 sub rsi, qword [tib] mov qword [to_in], rsi pop rsi - pspop r8 pspush rsi pspush r11 ret .empty: - pspop r8 pspush 0 pspush 0 ret ; }}} +defcode "type", type, 0 + pspop rdx + pspop rsi + mov rdi, 1 + mov rax, __NR_write + syscall + ret + defvar "state", state, 0, INTERPRET defvar "dp", dp, 0, 0 defvar "dp0", dp0, 0, 0 defvar "dp$", dp$, 0, 0 -defvar "tib", tib, 0, 0 ; todo set correct initial value -defvar "#tib", n_tib, 0, 0 ; todo set correct initial value +defvar "tib", tib, 0, initfile +defvar "#tib", n_tib, 0, initlen defvar ">in", to_in, 0, 0 defvar "latest", latest, 0, lfa_latest + +initfile: incbin "sanctuary.fs" +initlen equ $ - initfile |
