home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / TRYHEAP.ZIP / ITOH.ASM < prev    next >
Assembly Source File  |  1988-07-25  |  1KB  |  50 lines

  1.         title   ITOH - 16-bits to hex ASCII
  2.  
  3. ; ITOH ---  converts 16-bit unsigned integer
  4. ;           into a "hexadecimal" ASCII string.
  5. ; (C) 1988 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. _TEXT   segment word public 'CODE'
  13.  
  14.         assume  cs:_TEXT
  15.  
  16.         public  itoh
  17. itoh    proc    near
  18.  
  19.         push    cx              ; save registers 
  20.         push    dx
  21.  
  22.         mov     dx,4            ; initialize char. counter
  23.  
  24. itoh1:  mov     cx,4            ; isolate next four bits
  25.         rol     ax,cl
  26.         mov     cx,ax
  27.         and     cx,0fh
  28.         add     cx,'0'          ; convert to ASCII 
  29.         cmp     cx,'9'          ; is it 0-9?
  30.         jbe     itoh2           ; yes, jump
  31.         add     cx,'A'-'9'-1    ; add correction for A-F
  32.  
  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.  
  50.