fork download
  1. global _start
  2.  
  3. section .data
  4.  
  5. section .text
  6.  
  7. _start:
  8. ;put something for fib to calculate here
  9. call _fib
  10. je exit
  11.  
  12. _fib:
  13. push ebp
  14. mov ebp, esp
  15. sub esp, 16 ; ...AA-A-A-ND we've built the stack frame
  16. mov eax, [ebp+8]
  17. cmp eax, 2
  18. jae .recur
  19. xor edx, edx
  20. jmp .done
  21.  
  22. .recur:
  23. sub eax, 2
  24. push eax ; compute fib(n-2)
  25. call _fib
  26. mov [ebp-8], eax ; save returned value in 8-byte local variable...
  27. mov [ebp-4], edx ; ...in Little-Endian byte order.
  28. mov eax, [ebp+8] ; get argument again
  29. dec eax
  30. push eax ; compute fib(n-1)
  31. call _fib
  32. mov [ebp-16], eax ; save returned value in 8-byte local variable...
  33. mov [ebp-12], edx ; ...in Little-Endian byte order.
  34. ; the next steps are not as efficient as they could be...
  35. mov eax, [ebp-8]
  36. mov edx, [ebp-4] ; retrieve 1st computed value
  37. add eax, [ebp-16]
  38. adc edx, [ebp-12] ; add 2nd computed value
  39.  
  40. .done:
  41. mov esp, ebp
  42. pop ebp
  43. ret
  44.  
  45. exit:
  46. mov eax, 01h ; exit()
  47. xor ebx, ebx ; errno
  48. int 80h
  49.  
Success #stdin #stdout 0s 152KB
stdin
Standard input is empty
stdout
Standard output is empty