Advertisement
Guest User

Untitled

a guest
Jun 21st, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .386
  2. .model flat, stdcall
  3. option casemap : none
  4.  
  5. include \masm32\include\kernel32.inc
  6. include \masm32\include\masm32.inc
  7. include \masm32\include\msvcrt.inc
  8. includelib \masm32\lib\kernel32.lib
  9. includelib \masm32\lib\masm32.lib
  10. includelib \masm32\lib\msvcrt.lib
  11. include \masm32\macros\macros.asm
  12. .data
  13.     fstart dq 10.0
  14.     a dq 0.0
  15.     b dq 100.0
  16.     mid dq 0.0
  17.     num dq 32.0
  18.     n dd 5
  19.     m dd 0
  20.     eps dq 0.00001
  21.     two dq 2.0
  22.     zero dq 0.0
  23.     one dq 1.0
  24.     res dq 1.0
  25.     x dq 0.0
  26.     resMul dq 1.0
  27.    
  28. .code
  29. fun proc
  30.     fstp x
  31.     fld one
  32.     fstp res
  33.     mov eax, n
  34.     mov m, eax
  35. cicle:
  36.     mov eax, m
  37.     cmp eax, 0
  38.     je exitFun
  39.     mov ebx, 2
  40.     mov edx, 0
  41.     div ebx
  42.     cmp edx, 0
  43.     jne notzero
  44.     mov m, eax
  45.     fld x
  46.     fmul x
  47.     fstp x
  48.     jmp cicle
  49. notzero:
  50.     mov eax, m
  51.     sub eax, 1
  52.     mov m, eax
  53.     fld res
  54.     fmul x
  55.     fstp res
  56.     jmp cicle
  57. exitFun:
  58.     fld num
  59.     fsub res
  60.     fstp res
  61.     ret
  62.     fun endp
  63. start:
  64.     finit
  65. cicleMain:
  66.     fld one
  67.     fstp resMul
  68.     fld b
  69.     fsub a
  70.     fcom eps
  71.     fstsw ax
  72.     sahf
  73.     jb close
  74.     fld b
  75.     fadd a
  76.     fdiv two
  77.     fstp mid
  78.     fld mid
  79.     call fun
  80.     ffree st
  81.     fld resMul
  82.     fmul res
  83.     fstp resMul
  84.     fld a
  85.     call fun
  86.     ffree st
  87.     fld resMul
  88.     fmul res
  89.     fst resMul
  90.     fcom zero
  91.     fstsw ax
  92.     sahf
  93.     ja positive
  94.     fld mid
  95.     fstp b
  96.     ffree st
  97.     jmp cicleMain
  98. positive:
  99.     fld mid
  100.     fstp a
  101.     ffree st
  102.     jmp cicleMain
  103. close:
  104.     printf("%llf", mid)
  105.     xor eax, eax
  106.     ret
  107.     end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement