Back to Content

le: Wasm text instruction

files/en-us/webassembly/reference/numeric/le/index.md

latest1.5 KB
Original Source

The le instructions, short for less or equal, check if a number is less than or equal to another number. If the first number is less than or equal to the second number equal 1 will be pushed on to the stack, otherwise 0 will be pushed on to the stack.

The integer types have separate less or equal instructions for signed (le_s) and unsigned (le_u) numbers.

{{InteractiveExample("Wat Demo: le", "tabbed-taller")}}

wat
(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)
)
js
const url = "{%wasm-url%}";

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

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

Syntax

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.
InstructionBinary opcode
i32.le_s0x4C
i32.le_u0x4D
i64.le_s0x57
i64.le_u0x58
f32.le0x5F
f64.le0x65