Wasm Reference
  • Welcome
  • Nodejs WAT Compiler
  • Types
    • Functions
    • Globals
    • Linear Memory
    • Tables
    • Numbers
    • Text
  • Structures
    • IF
    • LOOP
  • Algorithms
    • Hello World
    • Estimate Pi
  • Maths Helper Algorithms
    • Pseudorandom Number Generator
    • Factorial
    • Dist
    • Map
    • Fract
    • RemF or ModF
    • Round
    • Clamp
    • Mix
    • Pow
    • Approx Sin
    • Approx Cos
    • Approx Tan
    • ToRad and ToDeg
Powered by GitBook
On this page

Was this helpful?

  1. Algorithms

Hello World

(module
  (import "console" "log" (func $log (param i32 i32)))
  (import "js" "mem" (memory 1))
  (data (i32.const 0) "Hello World")
  (func (export "hello")
    
    i32.const 0
    i32.const 11 
    call $log))

Imports

var memory = new WebAssembly.Memory({initial:1});

function consoleLogString(offset, length) {
    var bytes = new Uint8Array(memory.buffer, offset, length);
    var string = new TextDecoder('utf8').decode(bytes);
    console.log(string);
}


var importObject = { console: { log: consoleLogString }, js: { mem: memory } };
PreviousLOOPNextEstimate Pi

Last updated 5 years ago

Was this helpful?