userland/src/lib: add bloghelloworld
This commit is contained in:
parent
d582c3b14b
commit
a0805258e3
|
@ -0,0 +1,40 @@
|
|||
(module
|
||||
;; import functions from env
|
||||
(func $close (import "env" "close") (param i32) (result i32))
|
||||
(func $open (import "env" "open") (param i32 i32) (result i32))
|
||||
(func $read (import "env" "read") (param i32 i32 i32) (result i32))
|
||||
(func $write (import "env" "write") (param i32 i32 i32) (result i32))
|
||||
|
||||
;; memory
|
||||
(memory $mem 1)
|
||||
|
||||
;; constants
|
||||
(data (i32.const 200) "data")
|
||||
(data (i32.const 230) "Hello, world!\n")
|
||||
|
||||
(func $main (result i32)
|
||||
;; $fd is the file descriptor of the file we're gonna open
|
||||
(local $fd i32)
|
||||
|
||||
;; $fd = $open("data", O_CREAT|O_RDWR);
|
||||
(set_local $fd
|
||||
(call $open
|
||||
;; pointer to the file name
|
||||
(i32.const 200)
|
||||
;; flags, 42 for O_CREAT,O_RDWR
|
||||
(i32.const 42)))
|
||||
|
||||
;; $write($fd, "Hello, World!\n", 14);
|
||||
(call $write
|
||||
(get_local $fd)
|
||||
(i32.const 230)
|
||||
(i32.const 14))
|
||||
(drop)
|
||||
|
||||
;; $close($fd);
|
||||
(call $close
|
||||
(get_local $fd))
|
||||
(drop)
|
||||
|
||||
(i32.const 0))
|
||||
(export "main" (func $main)))
|
Loading…
Reference in New Issue