Advertisement
tinyevil

Untitled

Aug 15th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. /*
  2. function factorial(n:i32):i32{
  3. if ( n <= 1 ){
  4. return 1;
  5. }
  6. return factorial(n - 1) * n;
  7. }
  8. */
  9.  
  10. proc factorial(n:i32):i32{
  11. entry:
  12. c1 = call_intrin i32.le(n, 1)
  13. switch c1 {
  14. true -> label1
  15. false -> label2
  16. }
  17.  
  18. label1:
  19. store ret, 1
  20. kill c1
  21. ret
  22.  
  23. label2:
  24. n_m_1 = call_intrin i32.sub(n, 1)
  25. f_n_m_1 = call factorial(n_m_1)
  26. r = call_intrin i32.mul(f_n_m_1, n)
  27. store ret, r
  28. kill n_m_1
  29. kill f_n_m_1
  30. kill r
  31. ret
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement