换行
wrap 指令用于将 i64 类型的值转换为 i32 类型。如果该值大于 i32 的容纳范围,此操作将发生溢出(wrap),导致结果是一个不同的数值。
可以将 wrap 操作理解为将值 mod 232,或者理解为丢弃高 32 位,仅保留低 32 位来生成一个值。
试一试
(module
(import "console" "log" (func $log (param i32)))
(func $main
i64.const 10 ;; push an i64 onto the stack
i32.wrap_i64 ;; wrap from i64 to i32
call $log ;; log the result
)
(start $main)
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
语法
wat
;; push an i64 onto the stack
i64.const 10
;; wrap from i64 to i32
i32.wrap_i64
;; the top item on the stack will now be the value 10 of type `i32`
| 指令 | 二进制操作码 |
|---|---|
i32.wrap_i64 |
0xa7 |