home *** CD-ROM | disk | FTP | other *** search
/ PC Media 2 / PC MEDIA CD02.iso / share / prog / realasm1 / ftexp.asm < prev    next >
Encoding:
Assembly Source File  |  1993-07-18  |  1.7 KB  |  48 lines

  1. .286
  2. ;================================================
  3. ; invoke ftexp, real
  4. ;
  5. ; Returns e**(real)
  6. ;------------------------------------------------
  7. ;              x**1     x**2     x**3
  8. ; exp x = 1 +  ----  +  ----  +  ----  +  .......
  9. ;               1!       2!       3!
  10. ;
  11. ; 8 terms excluding unity term
  12. ;------------------------------------------------
  13. cseg          segment word public 'code'
  14.               assume  cs:cseg,ss:cseg
  15.               assume  ds:cseg,es:cseg
  16.  
  17.               include math.inc
  18.  
  19. ftexp         proc    near uses cx dx si di, real:NPR10
  20.               local   p:REAL10, f:REAL10, t:REAL10
  21.  
  22.               mov     si, real                  ;
  23.               lea     di, t                     ;
  24.  
  25.               invoke  load1, di                 ; t = 1.0
  26.               invoke  ftadd, di, si             ; t = 1.0 + real (1st term)
  27.               mov     cx, 8                     ; number of terms
  28.               mov     dx, 2                     ; starting power, factorial
  29.  
  30.               .WHILE (cx)                       ;
  31.                  invoke  movx, addr p, si, 5    ; p = real
  32.                  invoke  ftpower, addr p, dx    ; p = real**dx
  33.                  invoke  ftfact, addr f, dx     ; f = factorial dx
  34.                  invoke  ftdiv, addr p, addr f  ; p = real**dx / factorial dx
  35.  
  36.                  invoke  ftadd, di, addr p      ; t += term
  37.                  inc     dx                     ; powers, factorials + 1
  38.                  dec     cx                     ; continue
  39.               .ENDW
  40.  
  41.               invoke  movx, si, di, 5           ; real = t
  42.  
  43.               ret
  44. ftexp         endp
  45.  
  46. cseg          ends
  47.               end
  48.