RosettaCodeData/Task/Factorial/WebAssembly/factorial-5.wasm

30 lines
596 B
Plaintext

(module
;; iterative, generated by C compiler (LLVM) from recursive code!
(func $factorial (export "factorial") (param $p0 i32) (result i32)
(local $l0 i32) (local $l1 i32)
block $B0
get_local $p0
i32.eqz
br_if $B0
i32.const 1
set_local $l0
loop $L1
get_local $p0
get_local $l0
i32.mul
set_local $l0
get_local $p0
i32.const -1
i32.add
tee_local $l1
set_local $p0
get_local $l1
br_if $L1
end
get_local $l0
return
end
i32.const 1
)
)