fix readme

This commit is contained in:
zongor 2025-11-29 08:28:17 -08:00
parent 9d2053aef0
commit 32ae0eeb8f
1 changed files with 23 additions and 18 deletions

View File

@ -97,41 +97,46 @@ memory is managed via frame based arenas. function scopes defines a memory frame
heap allocations using the internal malloc opcode push pointers within this frame. when a frame exits, the pointer is reset like stack based gc. heap allocations using the internal malloc opcode push pointers within this frame. when a frame exits, the pointer is reset like stack based gc.
#+BEGIN_SRC sh #+BEGIN_SRC sh
global str terminal_namespace = "/dev/term/0"
global str prompt = "Enter a string:"
global str new_line = "\n"
function main () function main ()
int mode is $11 int mode $11;
str term is $10 str term $10;
malloc_immediate "/dev/term/0" -> term load_immediate terminal_namespace -> term
load_immediate 0 -> mode load_immediate 0 -> mode
syscall OPEN term mode -> term # Terminal term = open("/dev/term/0", 0); syscall OPEN term mode -> term // Terminal term = open("/dev/term/0", 0);
malloc_immediate "Enter a string:" -> $7 load_immediate prompt -> $7
string_length $7 -> $8 string_length $7 -> $8
syscall WRITE term $7 $8 # print prompt syscall WRITE term $7 $8 // print prompt
str user_string is $9 str user_string $9
load_immediate 32 -> $8 load_immediate 32 -> $8
malloc $8 -> user_string malloc $8 -> user_string
syscall READ term user_string $8 # read in max 32 byte string syscall READ term user_string $8 // read in max 32 byte string
call pln user_string call pln user_string -> void
exit 0 exit 0
function pln (str message is $0) function pln (str message $0)
str ts is $1 str ts $1
int mode is $5 int mode $5
int msg_length is $2 int msg_length $2
str nl is $3 str nl $3
int nl_length is $4 int nl_length $4
malloc_immediate "/dev/term/0" -> ts load_immediate terminal_namespace -> ts
load_immediate 0 -> mode load_immediate 0 -> mode
syscall OPEN ts mode -> ts # get terminal device syscall OPEN ts mode -> ts
strlen message -> msg_length strlen message -> msg_length
syscall WRITE ts message msg_length syscall WRITE ts message msg_length
malloc_immediate "\n" -> nl load_immediate new_line -> nl
strlen nl -> nl_length strlen nl -> nl_length
syscall WRITE ts nl nl_length syscall WRITE ts nl nl_length
return
#+END_SRC #+END_SRC