A 32-bit ISA with a set of Bytecode designed for a Stack-Based Virtual Machine. We can migrating low level software written in Rust, C, COBOL in a web browser at near native performance. It consists of web assembly Bytecode compiled to WASM binary.
Creating WASM Binaries
- Use Web Assembly Text
- Use Emscripten to convert C/C++ program to WASM Module
- Use AssemblyScript to convert TypeScript into WASM Module
WASM In the Browser
- WASM must be instantiated by a javascript handler, as it cannot talk to the DOM directly.
Boilerplates
JS Handler
// providing functions for WASM to callback
let imports = {
math : {
callback : x => console.log("result is", x);
}
}
let module = await WebAssembly.instantiateStreaming(fetch('main.wasm'), imports)
// using exports of WASM
let x = module.instance.exports.add(5,10)
WAT
(module
(import "math" "callback" (func $callback))
(export "add" (func $add))
(export "subtract" (func $subtract))
(func $add (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.add
local.set $sum ;; set result to sum
local.get $sum ;; put sum onto stack
call $callback ;; call callback with $sum
local.get $sum ;; put sum onto stack again
)
(func $subtract (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.sub
)
)
Compiling WAT
wat2wasm myfile.wat
Concepts
- WASM Module
- Web Assembly Text
- Web Assembly System Interface
- Web Assembly Binary Toolkit
- WASM Runtime
- ASMjs
- wasm-pack
- wasm-bindgen
- wasm2wat
Instructions
Guides
- https://rsms.me/wasm-intro
- https://invidious.yoshixi.net/watch?v=nW71Mlbmxt8
- https://sebastiano.tronto.net/blog/2025-06-06-webdev/
- https://invidious.yoshixi.net/watch?v=3sU557ZKjUs&listen=false
- https://invidious.yoshixi.net/watch?v=VGLnqkegX-g&listen=false
- https://webassembly.github.io/spec/
- https://developer.mozilla.org/en-US/docs/WebAssembly