小於或等於

le 指令,是 less or equal(小於等於)的縮寫,用於檢查一個數字是否小於或等於另一個數字。如果第一個數字小於或等於第二個數字,則將 1 推送至棧,否則將 0 推送至棧。

整數型別有分別針對有符號 (le_s) 和無符號 (le_u) 數字的“小於等於”指令。

試一試

(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.le_u ;; check if `10` is  less than or 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: false
}

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 less than or equal to '2'
i32.le_u

;; if $num is less than or equal to the `2`, `1` will be pushed on to the stack,
;; otherwise `0` will be pushed on to the stack.
指令 二進位制操作碼
i32.le_s 0x4C
i32.le_u 0x4D
i64.le_s 0x57
i64.le_u 0x58
f32.le 0x5F
f64.le 0x65