0x00 The Magic Bytes
00000000 00 61 73 6D 01 00 00 00 ; \0asm followed by version 1
; Every valid .wasm file starts here
A WebAssembly binary module always begins with the 4-byte magic number \0asm (hex 00 61 73 6D) followed by a 4-byte version field. The current version is 1.
0x08 Essential CLI Commands
Compile C/C++ to WASM with Emscripten
emcc hello.c -o hello.wasm
Build Rust to WASM with npm bindings
wasm-pack build --target web
Dump sections, imports, exports
wasm-objdump -x module.wasm
Decompile binary to readable WAT
wasm2wat module.wasm -o module.wat
Assemble WAT text to .wasm binary
wat2wasm module.wat -o module.wasm
Binaryen optimizer — shrink & speed up
wasm-opt -O3 input.wasm -o output.wasm
0x10 Minimal Browser Usage
// Fetch, compile, and instantiate a WASM module
const response = await fetch('module.wasm');
const bytes = await response.arrayBuffer();
const { instance } = await WebAssembly.instantiate(bytes, importObject);
// Call an exported function
const result = instance.exports.add(40, 2);
console.log(result); // 42
// Streaming compilation (preferred — starts compiling while downloading)
const { instance: inst } = await WebAssembly.instantiateStreaming(
fetch('module.wasm'),
importObject
);
0x18 File Extensions
| Extension | Format | Purpose |
|---|---|---|
.wasm |
Binary | Compiled WebAssembly module (the runtime artifact) |
.wat |
Text | Human-readable WebAssembly Text Format |
.wast |
Text | Extended text format for tests (assertions, modules) |
.wit |
Text | WebAssembly Interface Types (Component Model IDL) |