MDN / eqz: Wasm numeric instruction
MDN / eqz: Wasm numeric instruction
The eqz numeric instruction checks if a number is equal to zero.
(module
(import "env" "log_bool" (func $log_bool (param i32)))
(func $main
;; load `0` onto the stack
i32.const 0
i32.eqz ;; check if the previous number on the stack is equal to 0
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
value_type.eqz
value_type: The type of value the instruction is being run on. The following types support
eqz:i32i64
eqz: The
eqzinstruction. Must always be included after thevalue_typeand a period (.).
Type
[input] -> [output]
input: The input value.
output: The output value. If
inputis equal to0,1will be pushed on to the stack, otherwise0will be pushed on to the stack. The output values are integers.
Binary encoding
InstructionBinary formatExample text => binaryi32.eqz0x45i32.eqz => 0x45i64.eqz0x50i64.eqz => 0x50