Advertisement
Guest User

Compute Factorial

a guest
Oct 16th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .section .data
  2.  
  3. .section .text
  4.  
  5. .globl _start
  6.  
  7. .globl factorial
  8.  
  9. _start:
  10.  
  11. push $4
  12. call factorial
  13. add $4, %rsp
  14. mov %rax, %rbx
  15. mov $1, %rax
  16. int $0x80
  17.  
  18. .type factorial, @function
  19.  
  20. factorial:
  21. push %rbp
  22. mov %rsp, %rbp
  23. mov $1, %rax
  24. mov 8(%rbp), %rcx
  25. start_loop:
  26. cmp $1, %rcx
  27. je loop_exit
  28. imul %rcx, %rax
  29. dec %rcx
  30. jmp start_loop
  31. loop_exit:
  32. mov %rbp, %rsp
  33. pop %rbp
  34. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement