fork(1) download
  1. global _start
  2.  
  3. section .data
  4. outbuffer db '0000000000', 10,10
  5.  
  6. section .text
  7.  
  8. _start:
  9.  
  10. push 13 ; PUSH WANTED FIBBONACCI MEMBER INDEX HERE
  11. ; REMEMBER, IT MUST BE (N - 1)
  12. ; SO IF YOU WANT 14th MEMBER (LIKE HERE), YOU PUSH 13
  13. call fibo
  14. call printint
  15.  
  16. jmp exit
  17.  
  18. exit:
  19. mov eax, 01h ; exit()
  20. xor ebx, ebx ; errno
  21. int 80h
  22.  
  23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  24.  
  25. fibo:
  26. push ebp ; Retrieve parameter and put it
  27. push ebx ; Save previous parameter
  28. mov ebp,esp ; into EBX register
  29. add ebp,12 ;
  30. mov ebx,[ebp] ; EBX = Param
  31.  
  32. cmp ebx,1 ; Check for base case
  33. jle base ; It is base if (n <= 1)
  34.  
  35. lea ecx,[ebx-1]
  36. push ecx ; push N-1
  37. call fibo ; Calculate fibo for (EBX - 1)
  38. pop ecx ; remove N-1 off the stack
  39.  
  40. push eax ; save the result of fibo(N-1)
  41. lea ecx,[ebx-2]
  42. push ecx ; push N-2
  43. call fibo ; Calculate fibo for (EBX - 2)
  44. pop ecx ; remove N-2 off the stack
  45. pop ecx ; ecx = fibo(N-1)
  46. add eax,ecx ; eax = fibo(N-2) + fibo(N-1)
  47.  
  48. jmp end
  49.  
  50. base: ; Base case
  51. mov eax,1 ; The result would be 1
  52.  
  53. end:
  54. pop ebx ; Restore previous parameter
  55. pop ebp ; Release EBP
  56. ret
  57.  
  58.  
  59. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60.  
  61. printint:
  62. pushad
  63. mov ecx, 10d
  64. mov edi, 10d
  65. mov ebx, outbuffer+9
  66. innerprintloop:
  67. mov edx, 0h
  68. div edi
  69. add edx, '0' ; '0' - 0x48h
  70. mov [ebx], dl
  71. dec ebx
  72. loop innerprintloop
  73. mov ecx, outbuffer
  74. mov edx, 11
  75. call write
  76. popad
  77. ret
  78.  
  79. read:
  80. ;move where to read to ecx
  81. ;move length to edx
  82. mov eax, 03h ; 3 is recognized by the system as meaning "read"
  83. mov ebx, 00h ; read from standard input
  84. int 80h ; call the kernel
  85. ret
  86.  
  87. write:
  88. ;move what to write to ecx
  89. ;move length to edx
  90. mov eax, 04h ; the system interprets 4 as "write"
  91. mov ebx, 01h ; standard output (print to terminal)
  92. int 80h ; call the kernel
  93. ret
Success #stdin #stdout 0s 156KB
stdin
Standard input is empty
stdout
0000000377