home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / TPL60N19 / ARISOURC / F48FPOL.ASM < prev    next >
Assembly Source File  |  1993-01-24  |  6KB  |  123 lines

  1.  
  2. ; *******************************************************
  3. ; *                                                     *
  4. ; *     Turbo Pascal Runtime Library Version 6.0        *
  5. ; *     Real Polynomial Evaluation Routine              *
  6. ; *                                                     *
  7. ; *     Copyright (C) 1989-1992 Norbert Juffa           *
  8. ; *                                                     *
  9. ; *******************************************************
  10.  
  11.              TITLE   F48FPOL
  12.  
  13.              INCLUDE SE.ASM
  14.  
  15.  
  16. CODE         SEGMENT BYTE PUBLIC
  17.  
  18.              ASSUME  CS:CODE
  19.  
  20. ; Externals
  21.  
  22.              EXTRN   RealAdd:NEAR,RealMul:NEAR,RealMulFNoChk:NEAR
  23.              EXTRN   RealSqrNoChk:NEAR
  24.              EXTRN   RealMulNoChk:NEAR, shortmul:near
  25.  
  26. ; Publics
  27.  
  28.              PUBLIC  RealPoly
  29.  
  30. ;-------------------------------------------------------------------------------
  31. ; RealPoly is a routine that is used in the computation of all transcendental
  32. ; functions with the exception of the exponentiation routines. It is used to
  33. ; compute a polynomial approximation to the desired function. RealPoly computes
  34. ; either P(x^2)*x^2*x+x or P(x^2)*x^2 by way of Horner's method. A pointer to a
  35. ; table of coefficients for the polynomial is passed to the routine. The first
  36. ; coefficient is assumed to be of a special form, such that all but the sixteen
  37. ; most significant mantissa bits are zero. This makes the use of a special fast
  38. ; multiplication possible.
  39. ;
  40. ; INPUT:     DX:BX:AX  argument
  41. ;            CS:DI     pointer to a table of coefficients
  42. ;            CX        number of coefficients to be used
  43. ;            SI        SI <> 0 -> P(x^2) * x^2, SI = 0 -> P(x^2) * x^2 * x + x
  44. ;
  45. ; OUTPUT:    DX:BX:AX  approximated value of function
  46. ;
  47. ; DESTROYS:  AX,BX,CX,DX,SI,DI,Flags
  48. ;-------------------------------------------------------------------------------
  49.  
  50. RealPoly     PROC    NEAR
  51.              CMP     AL, 5Ch           ; abs(argument) < 2^-36 ?
  52.              JB      $poly_end         ; yes, result = arg. to machine precision
  53.              OR      SI, SI            ; test flag
  54.              PUSHF                     ; save flag setting
  55.              PUSH    DX                ; save
  56.              PUSH    BX                ;  argument
  57.              PUSH    AX                ;   on stack
  58.              PUSH    CX                ; save number of coefficients
  59.              PUSH    DI                ; save pointer to table of coefficients
  60.              CALL    RealSqrNoChk      ; multiply argument (!= 0) by itself
  61.              POP     DI                ; get back pointer to table
  62.              POP     CX                ; get back number of coefficients
  63.              PUSH    BP                ; save TURBO-Pascal base pointer
  64.              MOV     BP, SP            ; new base pointer to access argument
  65.              PUSH    DX                ; put
  66.              PUSH    BX                ;  square of argument
  67.              PUSH    AX                ;   on stack
  68.              PUSH    CX                ; save coefficient counter (CH = 0)
  69.              mov     cl, cs:[di]
  70.              inc     di
  71.              push    di
  72.              mov     di, cs:[di]
  73.              call    shortmul
  74.              pop     di
  75.              pop     cx
  76.              inc     di
  77.              inc     di
  78.              dec     cx
  79.              jz      $taylor_done
  80. ;             MOV     CL, CS:[DI]       ; load exponent of first coefficient
  81. ;             XOR     SI, SI            ; load mantissa middle byte of 1. coeff.
  82. ;             SUB     DI, 3             ; fake 6 coefficient bytes
  83. ;             PUSH    DI                ; save pointer to current coefficient
  84. ;             MOV     DI, CS:[DI+4]     ; load mantissa MSW of first coefficient
  85. ;             JMPS    $start            ; start polynomial approximation
  86. $taylor_loop:PUSH    CX                ; save coefficient counter
  87.              PUSH    DI                ; save pointer to current coefficient
  88.              MOV     CX, CS:[DI]       ; get
  89.              MOV     SI, CS:[DI+2]     ;  coefficient
  90.              MOV     DI, CS:[DI+4]     ;   from table
  91.              CALL    RealAdd           ; add coefficient
  92.              MOV     CX, [BP-6]        ; get
  93.              MOV     SI, [BP-4]        ;  saved
  94.              MOV     DI, [BP-2]        ;   square of argument
  95. $start:      CALL    RealMulfNoChk      ; multiply intermediate result by arg.
  96.              POP     DI                ; get pointer to current coefficient
  97.              POP     CX                ; get coefficient counter
  98.              ADD     DI, 6             ; pointer to next coefficient
  99.              LOOP    $taylor_loop      ; loop until coefficients used up
  100. $taylor_done:MOV     SP, BP            ; remove square of argument from stack
  101.              POP     BP                ; restore TURBO-Pascal base pointer
  102.              POP     CX                ; get back
  103.              POP     SI                ;  original
  104.              POP     DI                ;   argument x
  105.              POPF                      ; get polynomial type flag
  106.              JNZ     $poly_end         ;
  107.              PUSH    DI                ; save
  108.              PUSH    SI                ;  x on
  109.              PUSH    CX                ;   stack
  110.              CALL    RealMulfNoChk      ; compute P(x^2)*x^2*x
  111.              POP     CX                ; get
  112.              POP     SI                ;  x from
  113.              POP     DI                ;   stack
  114.              JMP     RealAdd           ; compute P(x^2)*x^2*x+x, exit v. RealAdd
  115. $poly_end:   RET                       ; done
  116. RealPoly     ENDP
  117.  
  118.              ALIGN   4
  119.  
  120. CODE         ENDS
  121.  
  122.              END
  123.