WebAssembly Binary Instruction Decoder
Decode raw WebAssembly binary instruction bytes into readable WASM mnemonics, immediate operands, LEB128 values, local and global indexes, branch depths, constants, memory alignments and offsets.
—
—
What Is a WebAssembly Binary Instruction?
WebAssembly instructions are encoded as compact binary opcodes followed by zero or more immediate operands. A WebAssembly function body is ultimately represented as a sequence of these instruction bytes.
Many integer immediates and indexes use LEB128 encoding, which allows small values to occupy fewer bytes than a fixed-width integer representation.
WebAssembly Opcode Examples
| Opcode | Instruction | Immediate |
|---|---|---|
| 0x0B | end | None |
| 0x0C | br | Label index |
| 0x0D | br_if | Label index |
| 0x10 | call | Function index |
| 0x20 | local.get | Local index |
| 0x21 | local.set | Local index |
| 0x23 | global.get | Global index |
| 0x28 | i32.load | memarg |
| 0x36 | i32.store | memarg |
| 0x41 | i32.const | Signed LEB128 |
| 0x42 | i64.const | Signed LEB128 |
| 0x6A | i32.add | None |
LEB128 in WebAssembly
LEB128 is a variable-length integer representation. Seven data bits are stored per byte, while bit 7 indicates whether another byte follows.
Example:
2A
Binary:
00101010
High continuation bit:
0
Unsigned value:
42i32.const
The i32.const instruction uses opcode 0x41 followed by a signed LEB128 32-bit integer.
41 2A
41:
i32.const
2A:
42
Decoded:
i32.const 42i64.const
i64.const uses opcode 0x42 and a signed LEB128 64-bit immediate. This allows both small and large signed 64-bit constants to be encoded compactly.
Local and Global Instructions
Instructions such as local.get, local.set, local.tee, global.get and global.set are followed by unsigned LEB128 indexes.
20 03
0x20:
local.get
0x03:
local index 3
Decoded:
local.get 3WebAssembly Memory Arguments
Load and store instructions include a memory argument containing alignment and offset values. Both values are encoded as unsigned LEB128 integers.
28 02 10
0x28:
i32.load
alignment exponent:
2
offset:
16
Decoded:
i32.load align=4 offset=16The alignment immediate stores an exponent, so an encoded value of 2 represents 2² = 4-byte alignment.
Control Flow Instructions
WebAssembly uses structured control flow with block, loop, if, else and end instructions. Branch instructions such as br and br_if reference a relative label depth rather than a raw machine-code address.
WebAssembly Numeric Instructions
Numeric opcodes cover integer and floating-point comparisons, arithmetic, bitwise operations, shifts, conversions and reinterpretations.
41 2A
41 08
6A
Decoded:
i32.const 42
i32.const 8
i32.addWebAssembly Binary Instruction Decoder FAQs
What does opcode 0x41 mean in WebAssembly?
What does opcode 0x42 mean?
What does opcode 0x6A mean?
What is LEB128?
Does this decoder parse complete .wasm modules?
How are memory offsets encoded?
What does WebAssembly end opcode 0x0B do?
Decode Raw WebAssembly Instructions
Inspect WASM instruction bytes from disassemblers, compiler output, browser tools, runtime traces and binary analysis with opcode, LEB128 and immediate operand decoding.