36 lines
1.1 KiB
Text
36 lines
1.1 KiB
Text
;; testing offsets and such
|
|
|
|
(module
|
|
;; import from wasi
|
|
;; fn fd_write(fd, *iovs, iovs_len, nwritten) -> bytes_written
|
|
(import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
|
|
|
|
;; create memory (size = 1 page = 64KiB)
|
|
(memory $foobar 1)
|
|
|
|
;; export memory - it's required, but we don't use it so the size is set to 0
|
|
(export "memory" (memory 0))
|
|
|
|
;; write string to memory (offset = 8 bytes)
|
|
(data (i32.const 20) "Hello, world!\n")
|
|
|
|
(func $main (export "_start")
|
|
;; iov.iov_base - pointer to string (offset = 0 bytes)
|
|
;; the string's offset is 8 bytes in memory
|
|
(i32.store (i32.const 12) (i32.const 20))
|
|
|
|
;; iov.iov_len - length of the hello world string (offset = 4 bytes)
|
|
;; the string's length is 14 bytes
|
|
(i32.store (i32.const 16) (i32.const 24))
|
|
|
|
(i32.const 1)
|
|
|
|
(call $fd_write
|
|
;; (i32.const 1) ;; fd: stdout = 1
|
|
(i32.const 12) ;; data: pointer to memory - this is the first memory we create (index 0)
|
|
(i32.const 1) ;; data_len: there's 1 string
|
|
(i32.const 2468) ;; nwritten: i don't care about this, write it wherever
|
|
)
|
|
drop ;; drop number of bytes written
|
|
)
|
|
)
|