home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / pcmag / vol7n19.arc / PP719.ARC / ITOH.ASM next >
Assembly Source File  |  1988-07-26  |  2KB  |  49 lines

  1. ;----------------------------------------------------------------------
  2. ; ITOH ---  converts 16-bit unsigned integer
  3. ;           into a "hexadecimal" ASCII string.
  4. ;
  5. ; Copyright (c) 1988, Ziff Communications Co.
  6. ; PC Magazine * Ray Duncan * November 15, 1988
  7. ;
  8. ; Call with     AX    = value to convert
  9. ;               DS:BX = address to store 4-character string
  10. ;
  11. ; Returns       AX, BX destroyed, other registers preserved
  12. ;----------------------------------------------------------------------
  13. _TEXT   segment word public 'CODE'
  14.  
  15.         assume  cs:_TEXT
  16.  
  17.         public  itoh
  18. itoh    proc    near
  19.  
  20.         push    cx              ; save registers 
  21.         push    dx
  22.  
  23.         mov     dx,4            ; initialize char. counter
  24. itoh1:
  25.         mov     cx,4            ; isolate next four bits
  26.         rol     ax,cl
  27.         mov     cx,ax
  28.         and     cx,0fh
  29.         add     cx,'0'          ; convert to ASCII 
  30.         cmp     cx,'9'          ; is it 0-9?
  31.         jbe     itoh2           ; yes, jump
  32.         add     cx,'A'-'9'-1    ; add correction for A-F
  33. itoh2:                          ; store this character
  34.         mov     [bx],cl
  35.         inc     bx              ; bump string pointer
  36.  
  37.         dec     dx              ; count characters converted
  38.         jnz     itoh1           ; loop, not four yet
  39.  
  40.         pop     dx              ; restore registers
  41.         pop     cx
  42.         ret                     ; back to caller
  43.  
  44. itoh    endp
  45.  
  46. _TEXT   ends
  47.  
  48.         end
  49.