Advertisement
Guest User

fibonacci

a guest
Jan 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int v[1001];
  7.  
  8. void fibonacci(int *, int)
  9. {
  10.     _asm {
  11.         mov eax, [ebp + 8];
  12.         mov ebx, [ebp + 12];
  13.         mov ecx, 0;
  14.         cmp ebx, 1;
  15.         je _one_element;
  16.         cmp ebx, 2;
  17.         je _two_elements;
  18.         mov[eax], 0;
  19.         mov[eax + 4], 1;
  20.         mov ecx, 2;
  21.     _loop:
  22.         cmp ecx, ebx;
  23.         jg _final;
  24.         mov edx, [eax + 4 * ecx - 4];
  25.         mov esi, [eax + 4 * ecx - 8];
  26.         add edx, esi;
  27.         mov[eax + 4 * ecx], edx;
  28.         inc ecx;
  29.         jmp _loop;
  30.     _one_element:
  31.         mov[eax], 0;
  32.         jmp _final;
  33.     _two_elements:
  34.         mov[eax], 0;
  35.         mov[eax + 4], 1;
  36.         jmp _final;
  37.     _final:
  38.     }
  39. }
  40.  
  41. int main()
  42. {
  43.     int n;
  44.     cin >> n;
  45.     _asm {
  46.         mov eax, n;
  47.         push eax;
  48.         lea eax, v;
  49.         push eax;
  50.         call fibonacci;
  51.         add esp, 8;
  52.     }
  53.  
  54.     int i;
  55.     for (i = 0; i < n; i++)
  56.         cout << v[i] << ' ';
  57.     cout << '\n';
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement