SHARE
TWEET

fibonacciStack

a guest Dec 9th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .intel_syntax noprefix
  2.     .global main
  3.     .text
  4. main:
  5.     mov eax, [esp+8]
  6.     mov eax, [eax+4]
  7.     push eax
  8.     call atoi
  9.     add esp, 4
  10.  
  11.     push eax
  12.     call fibo
  13.     add esp, 4
  14.  
  15.     push eax
  16.     push offset messg
  17.     call printf
  18.     add esp, 8
  19.     xor eax,eax
  20.     ret
  21.  
  22. fibo:
  23.     mov eax, [esp+4]
  24.     cmp eax, 2
  25.     jg skok
  26.     mov eax, 1
  27.     ret
  28.  
  29.     skok:
  30.         dec eax
  31.         push eax  // wrzucenie wartosci na stos
  32.         push eax //n-1
  33.         call fibo
  34.         add esp, 4
  35.         pop ebx //zdjecie wartosci ze stosu
  36.         push eax //wrzucenie wyniku fib(n-1) na stos
  37.         dec ebx //n-2
  38.         push ebx //wrzucenie n-2 na stos
  39.         call fibo
  40.         add esp, 4
  41.         pop ebx //zdjecie fib(n-1)
  42.         add eax, ebx //dodanie fib(n-1)+fib(n-2)
  43.         ret
  44.     .data
  45. messg:  .asciz "Wynik = %i\n"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top