home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / math / asc_f.asm next >
Assembly Source File  |  1986-01-17  |  5KB  |  112 lines

  1. ASC_F    PROC     NEAR
  2. ;****************************************************************
  3. ;                    converts a binary floating point operand
  4. ;                    to ASCII decimal. SI points to f.p. number
  5. ;                    DI points to end of ASCII location. Returns
  6. ;                    offset to first character (sign) in BX
  7. ;****************************************************************
  8.          PUSH     SI
  9.          PUSH     DI
  10.          SUB      DX,DX           ;clear DX & CX
  11.          MOV      CX,DX
  12. ;                            check for zero
  13.          MOV      AX,[SI]+2    
  14.          OR       AX,AX
  15.          JNZ      ASCF0
  16.          JMP      ASCF11
  17. ASCF0:   PUSH     BP              ;we'll use BP to address stack
  18. ;                            get sign
  19.          MOV      BL," "          ;assume sign positive
  20.          OR       AL,AL
  21.          JNS      ASCF1 
  22.          MOV      BL,"-"          ;sign is negative
  23. ASCF1:   PUSH     BX              ;save sign
  24. ;                          compute LOG10(X)=LOG2(X)xLOG10(2)
  25. ;                               =(E-1) x 0.3 (approximately)
  26. ;                               do this in fixed point
  27.          MOV      AL,AH           ;exponent in AX
  28.          MOV      AH,DH
  29.          SUB      AX,129          ;unbiased E=E-1 (E-128-1)
  30.          JGE      ASCF2           ;if negative
  31.          NEG      AX              ;make it positive
  32.          DEC      CX              ;and set flag in CX
  33. ASCF2:   MOV      BX,4CCDH        ;.3 decimal = .4CCD hex
  34.          MUL      BX              ;U=E * LOG10(2) =DX.AX
  35.          JCXZ     ASCF3           ;if E was negative
  36.          NEG      DX              ;make U negative
  37. ;                          adjust for number of places
  38. ASCF3:   SUB      DX,6            ;V=U+1-7
  39.          MOV      CX,DX
  40.          CMP      CX,-38          ;V < -38 will give overflow
  41.          JGE      ASCF4
  42.          MOV      CX,-38          ;so make it -38
  43. ;                          compute 10^V
  44. ASCF4:   MOV      SI,OFFSET IM2   ;set pointers to parameter
  45.          MOV      DI,OFFSET IM1   ;areas IM1 & IM2
  46. ASCF5:   PUSH     CX              ;keep V--it is decimal exponent
  47.          MOV      IM1,0           ;floating point ten in IM1
  48.          MOV      IM1+2,8420H
  49.          MOV      IM2,CX          ;V in IM2
  50.          CALL     IPOWER_F        ;raise 10 to the V
  51. ;                          compute W=ABS(X)/10^V
  52.          MOV      IM2,AX          ;10^V in IM2
  53.          MOV      IM2+2,DX
  54.          MOV      BP,SP
  55.          MOV      BX,[BP]+4       ;get address of X from stack
  56.          MOV      AX,[BX]         ;get f.p. operand X 
  57.          MOV      DX,[BX]+2
  58.          AND      DL,7FH          ;delete its sign--ABS(X)
  59.          MOV      IM1,AX          ;and put it in IM1
  60.          MOV      IM1+2,DX
  61.          CALL     DIV_F           ;DX:AX=W=IM1/IM2=ABS(X)/10^V
  62.          POP      CX              ;V in CX
  63. ;                           adjust W--maximum 7 digits
  64.          CMP      DX,9818H        ;if W >= 10^7
  65.          JA       ASCF6
  66.          JB       ASCF7
  67.          CMP      AX,9680H
  68.          JB       ASCF7 
  69. ASCF6:   ADD      CX,1            ;V=V+1
  70.          JMP      ASCF5           ;do it again
  71. ASCF7:   CMP      CX,-38          ;can V be decremented?
  72.          JLE      ASCF9
  73.          CMP      DX,9474H        ;if W <= 10^6-1
  74.          JA       ASCF9
  75.          JB       ASCF8
  76.          CMP      AX,23F0H
  77.          JA       ASCF9
  78. ASCF8:   DEC      CX              ;V=V-1
  79.          JMP      ASCF5           ;do it again
  80. ;                           convert to ASCII
  81. ASCF9:   MOV      BP,SP
  82.          MOV      DI,[BP]+4       ;point to ASCII location
  83.          MOV      IM1,AX          ;W in IM1
  84.          MOV      IM1+2,DX
  85.          MOV      IM2,CX          ;exponent in IM2
  86.          CALL     ASC16           ;convert exponent to ASCII      
  87.          MOV      DI,BX           ;BX points to sign
  88.          CMP BYTE PTR [DI]," "    ;if positive exponent
  89.          JNE      ASCF10
  90.          MOV BYTE PTR [DI],"+"    ;make sign explicit
  91. ASCF10:  DEC      DI              ;point to next byte
  92.          MOV BYTE PTR [DI],"E"    ;store the E
  93.          DEC      DI              ;and point to next postion
  94. ;                            convert mantissa--W
  95.          PUSH     DI
  96.          MOV      DI,OFFSET IM1   ;point to W
  97.          CALL     INT_F           ;convert W to two-word integer
  98.          MOV      [DI],AX         ;integer W in IM1
  99.          MOV      [DI]+2,DX
  100.          MOV      SI,DI           ;W is second operand
  101.          POP      DI              ;ASCII location is first
  102.          CALL     ASC32           ;convert it
  103.          POP      AX              ;get the sign
  104.          MOV      [BX],AL         ;and store it
  105.          POP      BP
  106.          JMP      EXIT
  107. ;                            here for zero input
  108. ASCF11:  MOV WORD PTR [DI],"0 "   ;this will be stored as " 0"
  109.          MOV      BX,DI
  110.          DEC      BX              ;offset in BX
  111.          JMP      EXIT        
  112. ASC_F    ENDP