9 lines
358 B
WebAssembly Text Format
9 lines
358 B
WebAssembly Text Format
;; recursive factorial(5) = 120, plus if/else with result
|
|
(module
|
|
(func $fact (param $n i32) (result i32)
|
|
(if (result i32) (i32.le_s (local.get $n) (i32.const 1))
|
|
(then (i32.const 1))
|
|
(else (i32.mul (local.get $n) (call $fact (i32.sub (local.get $n) (i32.const 1)))))))
|
|
(func (export "main") (result i32)
|
|
(call $fact (i32.const 5))))
|