Weniger oder gleich

Die le-Anweisungen, kurz für weniger oder gleich, überprüfen, ob eine Zahl kleiner oder gleich einer anderen Zahl ist. Wenn die erste Zahl kleiner oder gleich der zweiten Zahl ist, wird 1 auf den Stapel geschoben, andernfalls wird 0 auf den Stapel geschoben.

Die Ganzzahltypen haben separate Anweisungen für weniger oder gleich für vorzeichenbehaftete (le_s) und vorzeichenlose (le_u) Zahlen.

Probieren Sie es aus

(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 },
});

Syntax

wasm
;; 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.
Anweisung Binärer Opcode
i32.le_s 0x4C
i32.le_u 0x4D
i64.le_s 0x57
i64.le_u 0x58
f32.le 0x5F
f64.le 0x65