The Binary Format

12.1 Layout

Custom (name, producers, sourceMappingURL, DWARF .debug_*, target_features,...) Tag (exception handling)

Magic number: 00 61 73 6D   ("\0asm")
Version:      01 00 00 00   (version 1, also used by "Wasm 2.0/3.0" binaries)
Sections:     [id (1 byte)] [size (LEB128)] [contents] ...

12.2 Encoding Details

Integers use LEB128 variable-length encoding (unsigned/signed). Instructions are opcodes (1 byte, or a prefix byte + LEB index for extensions, e.g., 0xFC misc, 0xFD SIMD, 0xFE atomics, 0xFB GC).

The binary is designed for single-pass streaming validation and compilation: function bodies are self-contained, and section order enables a parallel compile.

wasm-objdump -h add.wasm     # section headers
wasm-objdump -d add.wasm     # disassembly with offsets
wasm-objdump -x add.wasm     # details: imports, exports, types
xxd add.wasm | head          # raw bytes
wasm-tools dump add.wasm     # annotated byte dump

12.3 Hand-Decoding Example (add.wasm)

00 61 73 6d 01 00 00 00            magic + version
01 07 01 60 02 7f 7f 01 7f         type section: 1 type, func (i32 i32) -> (i32)
03 02 01 00                        function section: 1 function of type 0
07 07 01 03 61 64 64 00 00         export section: "add" → func 0
0a 09 01 07 00 20 00 20 01 6a 0b   code: 1 body, 0 locals, local.get 0, local.get 1, i32.add, end