Declares a numeric constant value (of type i32
, i64
, f32
, or f64
), placing it on the stack 1
There are four different opcodes, to indicate the type of the value 2
Opcode | Instruction | Immediates | Stack Arity |
---|---|---|---|
0x41 |
i32.const |
||
0x42 |
i64.const |
||
0x43 |
f32.const |
||
0x44 |
f64.const |
!!! {.info}
For SIMD / Vectors, see v128.const
!!!
;; Places 10 on the stack
i32.const 10
;; Places 20 on the stack
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
i32.const 10
i32.const +20
i64.const -30
;; Integers can also be declared using hex format
i32.const 0x6D
f32.const 30.5
f32.const +32.57
f64.const -41.99
f64.const 12.34e+40
;; Hex-Float Format
f64.const 0x1p-1
;; Infinity
f64.const inf
;; NaN
f64.const nan
f64.const nan:0x123
Footnotes
-
Execution, Numeric Instructions, const - https://www.w3.org/TR/wasm-core-2/exec/instructions.html#exec-const ↩
-
Structure, Numeric Instructions - https://www.w3.org/TR/wasm-core-2/syntax/instructions.html#numeric-instructions ↩