Back to Content

const: Wasm text instruction

files/en-us/webassembly/reference/numeric/const/index.md

latest708 B
Original Source

The const instructions are used to declare numbers.

{{InteractiveExample("Wat Demo: const", "tabbed-standard")}}

wat
(module
  (import "console" "log" (func $log (param i32)))
  (func $main

    i32.const 10 ;; load a number onto the stack
    call $log ;; log the number

  )
  (start $main)
)
js
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });

Syntax

wat
;; push `5` onto the stack
i32.const 5
InstructionBinary opcode
i32.const0x41
i64.const0x42
f32.const0x43
f64.const0x44