This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(func $print_factorial (param $num i32) | |
(call $factorial (local.get $num) (i32.const 1)) | |
(; omitted for clarity ;) | |
) | |
(func $factorial (param $num i32) (param $res i32) (result i32) | |
(if (result i32) (i32.eqz (local.get $num)) | |
(then (return (local.get $res))) | |
(else | |
(return_call $factorial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void print_factorial(uint32_t num) | |
{ | |
printf(“%u\n”, factorial(num, 1)); | |
} | |
uint32_t factorial(uint32_t num, int res) | |
{ | |
if (num >= 1) | |
return factorial(num - 1, res * num); | |
return res; |