Advertisement
stasbar

Zadanie 2

Jan 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. extern double ciag(unsigned int  x);
  4.  
  5.  
  6. int main() {
  7.     int x = 5;
  8.     double wynik = ciag(x);
  9.  
  10.     printf("%lf", wynik);
  11.     getchar();
  12.     return 0;
  13. }
  14.  
  15. ////////////////////////////////////////////////
  16.  
  17.  .686
  18.  .model flat
  19.  public  _ciag
  20.  .code
  21. _ciag PROC
  22.     push ebp
  23.     mov ebp,esp
  24.  
  25.     FINIT
  26.     sprawdz_czy_jeden:
  27.     mov eax, [ebp+8]
  28.     cmp eax, 1
  29.     jne sprawdz_czy_dwa
  30.     mov eax, 5
  31.     push eax
  32.     FILD dword PTR[esp]
  33.     add esp, 4
  34.     jmp koniec
  35.  
  36.     sprawdz_czy_dwa:
  37.     cmp eax, 2
  38.     jne rekurencja
  39.     mov eax, 6
  40.     push eax
  41.     FILD dword PTR [esp]
  42.     add esp, 4
  43.     jmp koniec
  44.    
  45.     rekurencja:
  46.     dec eax ; x-1 (oryginal pozostaje w ebp+8 )
  47.     push eax
  48.     call _ciag  ; wynik w st0
  49.     add esp, 4
  50.     push 3
  51.     FILD dword PTR [esp] ; push 3
  52.     add esp,4
  53.     fsub st(0), st(1) ; 3 - ciag(x)
  54.     fxch st(1) ; zamiana st0 z st1 zeby mozna bylo pop
  55.     sub esp, 4
  56.     fstp dword PTR [esp] ; pop ciag(x)
  57.     add esp, 4
  58.  
  59.     fild dword PTR [ebp+8] ; push x
  60.     fdivp st(1), st(0) ; (3 - ciag(x)) / x
  61.    
  62.     koniec:
  63.     pop ebp
  64.     RET
  65. _ciag ENDP
  66. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement