Back to Content

global.get: Wasm text instruction

files/en-us/webassembly/reference/variables/global.get/index.md

latest735 B
Original Source

The global.get instruction loads the value of a global variable onto the stack.

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

wat
(module
  (import "console" "log" (func $log (param i32)))
  (global $var i32 (i32.const 10))
  (func $main

    global.get $var ;; load the value of $var variable onto the stack
    call $log ;; log the result

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

Syntax

wat
;; load the value of a global variable onto the stack
global.get $val
InstructionBinary opcode
global.get0x23