Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
176
0
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 f
  13.  
  14.         add esp, 4
  15.         push eax
  16.         push offset msg
  17.         call printf
  18.         add esp, 8
  19.         xor eax, eax
  20.         ret
  21.  
  22.     f:
  23.         cmp eax, 2
  24.         je return1
  25.         cmp eax, 1
  26.         je return1
  27.  
  28.         dec eax
  29.         push eax    #; n-1
  30.         call f
  31.         add esp, 4
  32.         push eax    #; f(n-1)
  33.        
  34.         mov eax, [esp+8]    #; get n
  35.         sub eax, 2
  36.         push eax    #; n-2
  37.         call f
  38.         add esp, 4
  39.  
  40.         add eax, [esp]
  41.         add esp, 4
  42.  
  43.         ret
  44.  
  45.     return1:
  46.         mov eax, 1
  47.         ret
  48.  
  49. .data
  50.     msg: .asciz "%d\n"
  51.  
  52.  
  53. #; if (n == 1 || n == 2) return 1;
  54. #; return f(n-2) + f(n-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement