Skip to content

Latest commit

 

History

History
45 lines (27 loc) · 1.29 KB

add.md

File metadata and controls

45 lines (27 loc) · 1.29 KB

add (addition)

Takes two operands (both of the same numeric type), adds them, and places the result on the stack 1 2 3.

$$ T.\mathsf{add} \enspace ( a: T, b: T ) \to a + b $$

Instructions

Opcode Instruction Stack Arity
0x6A i32.add $[ \mathsf{i32}, \mathsf{i32} ] \to [ \mathsf{i32} ]$
0x7C i64.add $[ \mathsf{i64}, \mathsf{i64} ] \to [ \mathsf{i64} ]$
0x92 f32.add $[ \mathsf{f32}, \mathsf{f32} ] \to [ \mathsf{f32} ]$
0xA0 f64.add $[ \mathsf{f64}, \mathsf{f64} ] \to [ \mathsf{f64} ]$

WAT Examples

Adding two constants

;; Places 2 values on the stack
i32.const 10
i32.const 20

;; Takes two values off of the stack (10 and 20), adds them, and
;; places the result (30) on the stack
i32.add

References

WebAssembly Core Specification

Footnotes

  1. Structure, Numeric Instructions - https://www.w3.org/TR/wasm-core-2/syntax/instructions.html#numeric-instructions

  2. Execution, Numerics, Integer Operations, iadd - https://www.w3.org/TR/wasm-core-2/exec/numerics.html#op-iadd

  3. Execution, Numerics, Floating-Point Operations, fadd - https://www.w3.org/TR/wasm-core-2/exec/numerics.html#op-fadd