Skip to content

Integer Arithmetic

Integer instructions wrap on overflow (two’s complement). Division by zero traps.

(module
(func (export "ops") (param $x i32) (param $y i32) (result i32)
(i32.add (local.get $x) (local.get $y)))
)

Also: i32.sub, i32.mul and all i64.* variants.

Signed vs unsigned matters for negatives:

(module
(func (export "divrem") (param $x i32) (param $y i32) (result i32)
(i32.div_s (local.get $x) (local.get $y)))
)

Also: i32.div_u, i32.rem_s, i32.rem_u and i64.* variants.