全局设置
global.set 指令用于设置全局变量的值。
试一试
(module
(import "console" "log" (func $log (param i32)))
(global $var (mut i32) (i32.const 0))
(func $main
i32.const 10 ;; load a number onto the stack
global.set $var ;; set the $var
global.get $var ;; load $var onto the stack
call $log ;; log the result
)
(start $main)
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
语法
wat
;; load the number 2 onto the stack
i32.const 2
;; store the number 2 in the variable $val
global.set $val
| 指令 | 二进制操作码 |
|---|---|
global.set |
0x24 |