home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / turbopas / tsrhelp.zip / CONVERT.INC < prev    next >
Text File  |  1992-05-29  |  2KB  |  50 lines

  1. ;---------------------------------------------------------------------------
  2. ; Program Name:  Convert.Inc
  3. ;
  4. ; Author:        Steve Poulsen
  5. ;
  6. ; This procedure converts a byte in AL to a printable string at DI.
  7. ; I.E. if AL = 67d then '67' will be put at DI.  
  8. ;
  9. ; Before:
  10. ;       AL = Byte to convert
  11. ;       DI = Pointer to location to store string 'must be long enough'
  12. ; After:
  13. ;       Nothing
  14. ; Changes:
  15. ;       Nothing
  16. ;---------------------------------------------------------------------------
  17.  
  18. Convert_Num Proc    Far
  19.  
  20.             Push BX            
  21.             Push CX
  22.             Push DX
  23.             Push DI
  24.             
  25.             Xor CX,CX               ; Clear CX, CX = number of digits
  26.             Mov BX,0Ah              ; Use base 10 or decimal
  27. Repeat_s:          
  28.             Mov AH,0                ; Make sure only a byte
  29.             Div BL                  ; Divide by 10.  Remainder is right digit
  30.             Inc CX                  ; Add a digit to CX
  31.             Add AH,30h              ; Add 30h for a printable character
  32.             Push AX                 ; Push the character on the stack
  33.             Cmp AL,0                ; Is there nothing left to divide?
  34.             JNE Repeat_s            ; Divide again
  35. Repeat_t:            
  36.             Pop DX                  ; Get digit
  37.             Dec CX                  ; CX tells us how many to pop off the stack
  38.             Mov [DI],DH             ; Put this in the data area 
  39.             Inc DI                  ; Move data area to next location
  40.             Cmp CX,0                ; Is this all the digits?
  41.             JNE Repeat_t            ; If not then get another
  42.             
  43.             Pop DI
  44.             Pop DX
  45.             Pop CX            
  46.             Pop BX
  47.  
  48.             Ret
  49. Convert_Num EndP
  50.