undar-lang/test/malloc.ul.ir

38 lines
850 B
Plaintext

function main ()
int mode $11;
str term $10;
malloc_immediate "/dev/term/0" -> term
load_immediate 0 -> mode
syscall OPEN term mode -> term # Terminal term = open("/dev/term/0", 0);
malloc_immediate "Enter a string:" -> $7
string_length $7 -> $8
syscall WRITE term $7 $8 # print prompt
str user_string $9
load_immediate 32 -> $8
malloc $8 -> user_string
syscall READ term user_string $8 # read in max 32 byte string
call pln user_string;
exit 0
function pln (str message $0)
str ts $1
int mode $5
int msg_length $2
str nl $3
int nl_length $4
malloc_immediate "/dev/term/0" -> ts
load_immediate 0 -> mode
syscall OPEN ts mode -> ts # get terminal device
strlen message -> msg_length
syscall WRITE ts message msg_length
malloc_immediate "\n" -> nl
strlen nl -> nl_length
syscall WRITE ts nl nl_length
return