From 357434991ee1966b67aafa7db13d26a7b2ccfb91 Mon Sep 17 00:00:00 2001 From: IgorCielniak Date: Fri, 26 Dec 2025 15:50:37 +0100 Subject: [PATCH] added a buffer of 64 bytes for some easily accesible persistent storage accesable via p@ and p! --- main.py | 2 ++ p.sl | 9 +++++++++ stdlib/stdlib.sl | 27 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 p.sl diff --git a/main.py b/main.py index 10118db..fb492c0 100644 --- a/main.py +++ b/main.py @@ -1793,6 +1793,8 @@ class Assembler: "align 16", "print_buf: resb PRINT_BUF_BYTES", "print_buf_end:", + "align 16", + "persistent: resb 64", ] def write_asm(self, emission: Emission, path: Path) -> None: diff --git a/p.sl b/p.sl new file mode 100644 index 0000000..0bf5c6c --- /dev/null +++ b/p.sl @@ -0,0 +1,9 @@ +import stdlib/stdlib.sl +import stdlib/io.sl + +: main + 12345 0 p! # store 12345 at offset 0 + 0 p@ puti cr # read and print value at offset 0 + 67890 8 p! # store 67890 at offset 8 + 8 p@ puti cr # read and print value at offset 8 +; diff --git a/stdlib/stdlib.sl b/stdlib/stdlib.sl index 0a26c6c..3dd7efb 100644 --- a/stdlib/stdlib.sl +++ b/stdlib/stdlib.sl @@ -1,3 +1,30 @@ +# Reserve 64 bytes in .bss +# persistent: resb 64 + +# : p@ ( offset -- n ) +:asm p@ { + mov rax, [r12] ; offset + lea rbx, [rel persistent] + add rax, rbx ; address = persistent + offset + mov rax, [rax] ; load value + mov [r12], rax ; store on stack + ret +} +; + +# : p! ( value offset -- ) +:asm p! { + mov rbx, [r12] ; offset + add r12, 8 + mov rax, [r12] ; value + lea rcx, [rel persistent] + add rcx, rbx ; address = persistent + offset + mov [rcx], rax ; store value + add r12, 8 ; pop value + ret +} +; + # : strlen ( addr -- len ) # for null terminated strings