home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / CONV07.ASM < prev    next >
Assembly Source File  |  1994-10-15  |  3KB  |  128 lines

  1.     page    66,132
  2. ;******************************** CONV07.ASM *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. comment 
  13. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( CONVERT )
  14. DWORD_TO_DEC_STRX - convert dword to decimal ascii with formating
  15. ; inputs: dx,ax = binary dword, dx=high word, ax=low word
  16. ;         ds:di = pointer to end of storage buffer.
  17. ; output:   di = pointer to start (left side) of decimal string.
  18. ;
  19. ; note:  The storage buffer must be initialized with all spaces if
  20. ;        leading blanks are utilized.
  21. ;
  22. ;        This routine right justifies the decimal ascii in a buffer
  23. ;        and adds commas between each grouping of three digits.
  24. ;        Normally, this routine is used to display numbers in columns
  25. ;        with right edge lined up.
  26. ;
  27. ;        Beware, the input buffer pointer must point to the end of the
  28. ;        buffer and not the start.
  29. ;
  30. ;        This routine can be used to display numbers right justified or
  31. ;        left justified, depending upon whether the buffer start is used
  32. ;        or returned DI is used.
  33. ;* * * * * * * * * * * * * *
  34. 
  35.     public    DWORD_TO_DEC_STRX
  36. DWORD_TO_DEC_STRX    PROC    FAR
  37.     call    dword_convert
  38.     retf
  39. DWORD_TO_DEC_STRX    ENDP
  40. comment 
  41. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( CONVERT )
  42. DWORD_TO_DEC_CRTX - convert dword to decimal ascii and display
  43. ; inputs: dx,ax = binary dword, dx=high word, ax=low word
  44. ; output: none
  45. ;
  46. ; note:  Display cursor should be at right end of area for decimal value.
  47. ;        The value is displayed from right to left and commas added to
  48. ;        separate every 3 characters.
  49. ;* * * * * * * * * * * * * *
  50. 
  51.     public    DWORD_TO_DEC_CRTX
  52. DWORD_TO_DEC_CRTX    PROC    FAR
  53.         cld
  54.         apush    ax,di,dx,ds
  55.  
  56.         push    cs
  57.         pop    ds
  58.         mov    di,offset text_store
  59. ;
  60. ; clear the text build area
  61. ;
  62. db_clear:    mov    byte ptr ds:[di],' '
  63.         inc    di
  64.         cmp    di,offset text_end -1
  65.         jne    db_clear
  66.  
  67.         call    dword_convert
  68.                 
  69.         mov    dx,offset text_store
  70.         mov    ah,9
  71.         int    21h
  72.         apop    ds,dx,di,ax
  73.         retf
  74. DWORD_TO_DEC_CRTX    ENDP
  75. ;----------------------------------------------------------------------------
  76.  
  77. ten        dw    10
  78. comma_count    db    0
  79. text_store    db    10 dup (20h)
  80. text_end    db    '$'
  81. ;----------------------------------------------------------------------------
  82. ; dword_convert - convert dword to decimal ascii and store using ES:DI
  83. ;   inputs:  dx,ax = binary value
  84. ;            es:di = storage point
  85. ;  output:  di = pointer to start of decimal string
  86. ;
  87. dword_convert:
  88.         apush    ax,bx,dx
  89.         mov    cs:comma_count,4  
  90. ;
  91. ; convert one character each loop.  The least segnificant ditits are
  92. ; converted first.
  93. ;
  94. dd_loop:    push    ax
  95.         mov    ax,dx
  96.         xor    dx,dx
  97.         div    cs:ten
  98.         mov    bx,ax
  99.         pop    ax
  100.         div    cs:ten
  101.         xchg    bx,dx
  102.  
  103. ; dx,ax = quotient
  104. ;    bx = remainder
  105.  
  106.         dec    comma_count
  107.         jnz    not_yet1        ;jmp if not time for comma
  108.         mov    comma_count,3
  109.         mov    byte ptr es:[di],','
  110.         dec    di
  111. not_yet1:    add    bl,30h
  112.         mov    byte ptr es:[di],bl
  113.         dec    di
  114. ;
  115. ; dx,ax = quotient
  116. ;    bx = remainder
  117.  
  118.         or    ax,ax
  119.         jnz    dd_loop
  120.         or    dx,dx
  121.         jnz    dd_loop
  122.         inc    di            ;point at last char. stored.
  123.         apop    dx,bx,ax
  124.         ret
  125.  
  126. LIBSEG    ENDS
  127.     end
  128.