Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- function factorial(n:i32):i32{
- if ( n <= 1 ){
- return 1;
- }
- return factorial(n - 1) * n;
- }
- */
- proc factorial(n:i32):i32{
- entry:
- c1 = call_intrin i32.le(n, 1)
- switch c1 {
- true -> label1
- false -> label2
- }
- label1:
- store ret, 1
- kill c1
- ret
- label2:
- n_m_1 = call_intrin i32.sub(n, 1)
- f_n_m_1 = call factorial(n_m_1)
- r = call_intrin i32.mul(f_n_m_1, n)
- store ret, r
- kill n_m_1
- kill f_n_m_1
- kill r
- ret
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement