Sha256: 1387201466849191fb4eb30c0226c7ac1e8f503f8ab2258b403089f31349cf9b

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

{{libheader|WASI}}
(module $helloworld

    ;;Import fd_write from WASI, declaring that it takes 4 i32 inputs and returns 1 i32 value
    (import "wasi_unstable" "fd_write"
        (func $fd_write (param i32 i32 i32 i32) (result i32))
    )

    ;;Declare initial memory size of 32 bytes
    (memory 32)

    ;;Export memory so external functions can see it
    (export "memory" (memory 0))
 
    ;;Declare test data starting at address 8
    (data (i32.const 8) "Hello world!\n")
 
    ;;The entry point for WASI is called _start
    (func $main (export "_start")
        
        ;;Write the start address of the string to address 0
        (i32.store (i32.const 0) (i32.const 8)) 
 
        ;;Write the length of the string to address 4
        (i32.store (i32.const 4) (i32.const 13))

        ;;Call fd_write to print to console
        (call $fd_write
            (i32.const 1) ;;Value of 1 corresponds to stdout
            (i32.const 0) ;;The location in memory of the string pointer
            (i32.const 1) ;;Number of strings to output
            (i32.const 24) ;;Address to write number of bytes written
        )
        drop ;;Ignore return code
    )
)

Version data entries

10 entries across 7 versions & 1 rubygems

Version Path
zettacode-0.1.7 files.zettacode/hello_world.text/webassembly.txt
zettacode-0.1.6 files.zettacode/hello_world.text/webassembly.txt
zettacode-0.1.6 files.zettacode2/hello_world.text/webassembly.txt
zettacode-0.1.5 files.zettacode/hello_world.text/webassembly.txt
zettacode-0.1.5 files.zettacode2/hello_world.text/webassembly.txt
zettacode-0.1.4 files.zettacode/hello_world.text/webassembly.txt
zettacode-0.1.4 files.zettacode2/hello_world.text/webassembly.txt
zettacode-0.1.3 files.zettacode/hello_world.text/webassembly.txt
zettacode-0.1.2 files.zettacode/hello_world.text/webassembly.txt
zettacode-0.1.1 zettacode.files/hello_world.text/webassembly.txt