不等於

ne 指令,即 not equal(不等於)的縮寫,用於檢查兩個數字是否不相等。如果數字不相等,則將 1 推送到堆疊;否則,將 0 推送到堆疊。

試一試

(module
  (import "env" "log_bool" (func $log_bool (param i32)))
  (func $main
    ;; load `10` and `2` onto the stack
    i32.const 10
    i32.const 2

    i32.ne ;; check if `10` is not equal to `2`
    call $log_bool ;; log the result
  )
  (start $main)
)
const url = "{%wasm-url%}";

function log_bool(value) {
  console.log(Boolean(value));
  // Expected output: true
}

await WebAssembly.instantiateStreaming(fetch(url), {
  env: { log_bool },
});

語法

wat
;; load 2 numbers on to the stack
local.get $num
i32.const 2

;; check if $num is not equal to '2'
i32.ne

;; if $num is not equal to `2`, `1` will be pushed on to the stack,
;; otherwise `0` will be pushed on to the stack.
指令 二進位制操作碼
i32.ne 0x47
i64.ne 0x52
f32.ne 0x5c
f64.ne 0x62