Advertisement
The_KGB

ASM factorial of 5

Jul 20th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #factoral and call a recursive function
  2.  
  3. .section .data
  4. .section .text
  5.  
  6. .globl _start
  7. .globl factorial
  8.  
  9. _start:
  10. pushl $5
  11.  
  12. call factorial
  13. addl $5, %esp
  14.  
  15. movl %eax, %ebx
  16. movl $1, %eax
  17. int $0x80
  18.  
  19. .type factorial,@function
  20. factorial:
  21. pushl %ebp
  22.  
  23. movl %esp, %ebp
  24. movl 8(%ebp), %eax
  25.  
  26. cmpl $1, %eax
  27.  
  28. je end_factorial
  29. decl %eax
  30. pushl %eax
  31. call factorial
  32. movl 8(%ebp), %ebx
  33.  
  34. imull %ebx, %eax
  35.  
  36. end_factorial:
  37. movl %ebp, %esp
  38. popl %ebp
  39.  
  40. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement