home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 08 / decconv.asc < prev    next >
Text File  |  1991-07-23  |  896b  |  44 lines

  1. _DECIMAL FRACTIONAL CONVERSION_
  2. by Don Morgan
  3.  
  4.  
  5. [EXAMPLE 1: Fractional Conversion Routine]
  6.  
  7.  
  8. mantissa    word    ?
  9. dec_frac    word    ?
  10. ;
  11. ; frac- conversion of decimal fractional part to hex
  12. ; enter with packed decimal word in ax
  13. ; returns with result in dx\
  14. ;DS is assumed to point into the Data Segment
  15. frac    proc
  16.     mov cx,10h    ;number of bits in resulting mantissa
  17. cnvt:
  18.     add al,al     ;could add to self, we will see
  19.     daa
  20.     mov bl,al
  21.     mov al,ah
  22.     jnc nc1
  23.     add al,al     ;could add to self, we will see
  24.     daa
  25.     inc al
  26.     jmp short nc2
  27. nc1:
  28.     add al,al     ;could add to self, we will see
  29.     daa
  30. nc2:
  31.     mov ah,al
  32.     mov al,bl
  33.     rcl dx,1
  34.     loop    cnvt
  35.     sub ax,5000h
  36.     jc  end_frac
  37.     inc dx    ;for round off
  38. end_frac:
  39.     mov word ptr mantissa,dx
  40.     ret
  41. frac    end
  42.  
  43.