換行

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