Skip to content

Instantly share code, notes, and snippets.

@tomoliv30
Created July 11, 2022 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoliv30/f767c2c54a2c45a2ce57bafacceba0ec to your computer and use it in GitHub Desktop.
Save tomoliv30/f767c2c54a2c45a2ce57bafacceba0ec to your computer and use it in GitHub Desktop.
(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
(i32.sub (local.get $num) (i32.const 1))
(i32.mul (local.get $num) (local.get $res))
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment