You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.2 KiB
Plaintext
57 lines
1.2 KiB
Plaintext
;; Currently using a hard-coded struct at location 0
|
|
(import "wasi_unstable" "fd_write" (func $fd_write (param $file_descriptor i32) (param $io_vectors i32) (param $io_vecnum i32) (param $num_written_ptr i32) (result i32)))
|
|
|
|
(func $print (param $location i32) (param $length i32) (result i32)
|
|
(local $structLoc i32)
|
|
(local $resultLoc i32)
|
|
(local $resultCode i32)
|
|
|
|
i32.const 8 ;; 2 x 4bytes per i32
|
|
call $memory_alloc
|
|
local.set $structLoc
|
|
|
|
i32.const 4
|
|
call $memory_alloc
|
|
local.set $resultLoc
|
|
|
|
;; put location at offset 0
|
|
local.get $structLoc
|
|
local.get $location
|
|
i32.store
|
|
|
|
;; put length at offset 4
|
|
local.get $structLoc
|
|
i32.const 4
|
|
i32.add
|
|
local.get $length
|
|
i32.store
|
|
|
|
;; call params
|
|
i32.const 1 ;; file file_descriptor
|
|
local.get $structLoc ;; array pointer
|
|
i32.const 1 ;; array length
|
|
local.get $resultLoc ;; result pointer
|
|
|
|
call $fd_write
|
|
local.tee $resultCode
|
|
|
|
;; if 0 code, make sure all bytes were written
|
|
i32.eqz
|
|
if
|
|
local.get $resultLoc
|
|
local.get $length
|
|
i32.lt_u
|
|
if
|
|
i32.const 1
|
|
return
|
|
end
|
|
|
|
i32.const 0
|
|
return
|
|
end
|
|
|
|
;; otherwise return code
|
|
local.get $resultCode
|
|
return
|
|
)
|