home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / math / ipower_f.asm < prev    next >
Assembly Source File  |  1986-01-17  |  4KB  |  93 lines

  1. IPOWER_F PROC      NEAR
  2. ;**************************************************************
  3. ;                       raises floating point mantissa pointed
  4. ;                       by DI to 16 bit integer exponent pointed
  5. ;                       to by SI
  6. ;**************************************************************
  7.          PUSH      SI
  8.          PUSH      DI
  9.          SUB       AX,AX              ;clear registers
  10.          MOV       CX,AX
  11. ;                               get mantissa
  12.          MOV       BX,[DI]            ;f.p. mantissa in CX:BX
  13.          OR        CX,[DI]+2
  14.          JNZ       E0          ;check for zero mantissa
  15.          SUB       DX,DX              ;set result in DX:AX
  16.          MOV       AX,DX              ;to zero
  17.          JMP       EXIT               ;and return
  18. ;                               get result sign
  19. E0:      MOV       DX,0080h           ;isolate sign
  20.          AND       DX,CX              ;in DX
  21.          PUSH      DX                 ;and save it
  22. ;                               get exponent
  23.          MOV       DI,AX              ;clear DI
  24.          OR        DI,[SI]            ;OR  exponent into DI
  25.          MOV       SI,DI              ;save it temporarily in DI
  26.          JS        E1                 ;jump if negative exponent
  27.          JNZ       E2          ;check for zero exponent
  28.          MOV       DX,8100H           ;zero--set result to 1
  29.          MOV       AX,0
  30.          POP       CX                 ;get sign
  31.          OR        DX,CX              ;and restore it
  32.          JMP       EXIT               ;and return
  33. ;
  34. E1:      NEG       DI                 ;make exponent positive
  35. ;
  36. E2:      MOV       IM1,AX             ;store Y--initially = +1
  37.          MOV       IM1+2,8100H
  38.          MOV       IM2,BX             ;store Z
  39.          MOV       IM2+2,CX
  40. ;
  41.          PUSH      SI                 ;save original exponent
  42. ;
  43. E3:      SHR       DI,1               ;N=N/2
  44.          JNC       E4                 ;jump if N was even
  45. ;                                compute Y=Z*Y
  46.          PUSH      DI                 ;save N
  47.          MOV       SI, OFFSET IM1     ;address of Y in SI
  48.          MOV       DI, OFFSET IM2     ;address of Z in DI
  49.          CALL      MUL_F              ;Y=Y*Z--product in DX:AX
  50.          OR        BX,BX              ;check completion status
  51.          JNZ       E8                 ;jump if error
  52.          MOV       IM1,AX             ;store Y
  53.          MOV       IM1+2,DX
  54. ;                                if N=0 then quit
  55.          POP       DI                 ;get exponent
  56.          OR        DI,DI
  57.          JZ        E5
  58. ;                                compute Z*Z
  59. E4:      PUSH      DI                 ;save N
  60.          MOV       SI, OFFSET IM2     ;address of Z in SI
  61.          MOV       DI,SI              ;and in DI
  62.          CALL      MUL_F              ;Z*Z--product in DX:AX
  63.          OR        BX,BX              ;check completion status
  64.          JNZ       E8
  65.          MOV       IM2,AX             ;store Z
  66.          MOV       IM2+2,DX
  67.          POP       DI
  68. ;
  69.          JMP       E3                 ;repeat for next N
  70. ;                                compute reciprocal if
  71. E5:      POP       CX                 ;original exponent
  72.          OR        CX,CX
  73.          JNS       E6                 ;was negative
  74.          MOV       DX,8100H           ;set up dividend of 1
  75.          SUB       AX,AX
  76.          MOV       IM2,AX             ;put it in IM2
  77.          MOV       IM2+2,DX
  78.          MOV       SI, OFFSET IM1
  79.          MOV       DI, OFFSET IM2
  80.          CALL      DIV_F              ;reciprocal in DX:AX
  81.          OR        BX,BX              ;check completion code
  82.          JNZ       E9
  83. ;                                set result sign
  84. E6:      POP       DI
  85.          OR        DX,DI
  86.          JMP       EXIT
  87.  
  88. ;                                here if error
  89. E8:      POP       DI                 ;pop stack
  90.          POP       DI
  91. E9:      POP       DI
  92.          JMP       EXIT               ;and return
  93. IPOWER_F ENDP