undar-lang/test/malloc.asm.lisp

26 lines
756 B
Common Lisp

((code
(label main
(load-immediate $0 &terminal-namespace) ; get terminal device
(load-immediate $1 &help) ; print help message
(push $1)
(call &pln)
(load-immediate $1 32) ; read in a string of max 32 char length
(malloc $2 $1) ; allocate memory for the string
(syscall READ $0 $3 $1 $2) ; read the string
(push $3)
(call &pln) ; print the string
(halt))
(label pln
(load-immediate $0 &terminal-namespace)
(load-immediate $3 &new-line)
(pop $1)
(string-length $2 $1)
(syscall WRITE $0 $1 $2)
(string-length $4 $3)
(syscall WRITE $0 $3 $4)
(return)))
(data
(label terminal-namespace "/dev/term/0")
(label help "Enter a string: ")
(label new-line "\n")))