home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / ADVMSDOS.ZIP / HEXASC.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-06-19  |  896 b   |  42 lines

  1. ;
  2. ; HEXASC --- converts a binary 16-bit number into
  3. ;            a "hexadecimal" ASCII string.
  4. ;
  5. ; Copyright (C) 1984 Ray Duncan
  6. ;
  7. ; Call with     AX    = value to convert
  8. ;        DS:BX = address to store 4-character string
  9. ;
  10. ; Returns    AX, BX destroyed, other registers preserved
  11. ;
  12. hexasc    proc    near
  13.  
  14.     push    cx    ; save registers 
  15.     push    dx
  16.     mov    dx,4    ; initialize character counter
  17.  
  18. hexasc1:
  19.     mov    cx,4    ; isolate next four bits
  20.     rol    ax,cl
  21.     mov    cx,ax
  22.     and    cx,0fh
  23.     add    cx,'0'    ; convert to ASCII 
  24.     cmp    cx,'9'    ; is it 0-9?
  25.     jbe    hexasc2    ; yes, jump
  26.             ; add fudge factor for A-F
  27.     add    cx,'A'-'9'-1
  28.  
  29. hexasc2:        ; store this character
  30.     mov    [bx],cl
  31.     inc    bx    ; bump string pointer
  32.  
  33.     dec    dx    ; count characters converted
  34.     jnz    hexasc1 ; loop, not four yet
  35.  
  36.     pop    dx    ; restore registers
  37.     pop    cx
  38.     ret        ; back to caller
  39.  
  40. hexasc    endp
  41. ;
  42.