Expand description
WebAssembly instruction set.
StructsΒ§
- Expression
- Function bodies, initialization values for globals, and offsets of element or data segments are given as expressions, which are sequences of instructions terminated by an πΎππ½ marker. In some places, validation restricts expressions to be constant, which limits the set of allowable instructions.
- Memory
Argument - Argument to load and store instructions that contains an address offset and the expected alignment (expressed as the exponent of a power of 2).
EnumsΒ§
- Block
Type - A structured instruction can consume input and produce output on the operand stack according to its annotated block type. It is given either as a type index that refers to a suitable function type, or as an optional value type inline, which is a shorthand for the function type []β[valtype?].
- Control
Instruction - Instructions in this group affect the flow of control. The π»π ππΌπ, π πππ and ππΏ instructions are structured instructions. They bracket nested sequences of instructions, called blocks, terminated with, or separated by, πΎππ½ or πΎπ ππΎ pseudo-instructions. As the grammar prescribes, they must be well-nested.
- Instruction
- WebAssembly code consists of sequences of instructions. Its computational model is based on a stack machine in that instructions manipulate values on an implicit operand stack, consuming (popping) argument values and producing or returning (pushing) result values. In addition to dynamic operands from the stack, some instructions also have static immediate arguments, typically indices or type annotations, which are part of the instruction itself. Some instructions are structured in that they bracket nested sequences of instructions. The following sections group instructions into a number of different categories.
- Memory
Instruction - Instructions in this group are concerned with linear memory. Memory is accessed with π ππΊπ½ and πππππΎ instructions for the different value types. They all take a memory immediate memarg that contains an address offset and the expected alignment (expressed as the exponent of a power of 2). Integer loads and stores can optionally specify a storage size that is smaller than the bit width of the respective value type. In the case of loads, a sign extension mode sx is then required to select appropriate behavior.
- Numeric
Instruction - Numeric instructions provide basic operations over numeric values of specific type. These operations closely match respective operations available in hardware.
- Parametric
Instruction - Instructions in this group can operate on operands of any value type.
- Reference
Instruction - Instructions in this group are concerned with accessing references. These instruction produce a null value, check for a null value, or produce a reference to a given function, respectively.
- Sign
Extension - Some integer instructions come in two flavors, where a signedness annotation sx distinguishes whether the operands are to be interpreted as unsigned or signed integers. For the other integer instructions, the use of twoβs complement for the signed interpretation means that they behave the same regardless of signedness.
- Table
Instruction - Instructions in this group are concerned with tables table. An additional instruction that accesses a table is the control instruction πΌπΊπ π _πππ½πππΎπΌπ.
- Variable
Instruction - Variable instructions are concerned with access to local or global variables. These instructions get or set the values of variables, respectively. The π ππΌπΊπ .ππΎπΎ instruction is like π ππΌπΊπ .ππΎπ but also returns its argument.