fork(5) download
  1. .data
  2. a : .long 6
  3. r : .long 0
  4. out : .string "result %d\n"
  5. .text
  6. .global main
  7. fib:
  8. pushl %ebp
  9. movl %esp, %ebp
  10. movl 8(%ebp), %eax
  11. cmpl $0, %eax #fib(0)=0
  12. je endf
  13. cmpl $1, %eax #fib(1)=1
  14. je endf
  15. decl %eax #eax=n-1
  16. pushl %eax #set arg
  17. call fib #re in ecx
  18. popl %eax #get n-1
  19. decl %eax #eax=n-2
  20. pushl %ecx #save result for n-1
  21. pushl %eax #set arg
  22. call fib #res in ecx
  23. popl %eax # eax=n-2, discard
  24. popl %eax # eax=fib(n-1)
  25. addl %eax, %ecx #fib(n)=fib(n-1)+fib(n+2)
  26. movl %ebp,%esp #Exit
  27. popl %ebp
  28. ret
  29. endf:
  30. movl %eax, %ecx#fib(0) or fib(1) to %ebx
  31. movl %ebp,%esp
  32. popl %ebp
  33. ret
  34.  
  35. main:
  36. pushl a #stack [a]
  37. call fib #result in %ecx
  38. popl %eax # remove arg to fib
  39. pushl %ecx
  40. pushl $out
  41. call printf
  42. addl $8, %esp
  43. xor %eax, %eax
  44. ret
  45.  
Success #stdin #stdout 0.01s 1524KB
stdin
Standard input is empty
stdout
result 8