include	clib.inc
include	string.inc

_TEXT	SEGMENT

atohex proc DIST pascal public uses si di string:dword
	mov di,word ptr string
	invoke strlen, string
	test ax,ax
	jz atohex_end
	cmp ax,64
	jnb atohex_end
	dec ax
	mov si,di
	add si,ax
	add ax,ax
	add di,ax
	mov byte ptr es:[di+2],0
    atohex_loop:
	mov al,es:[si]
	mov ah,al
	shr al,4
	and ah,15
	add ax,'00'
	cmp al,'9'
	jbe atohex_01
	add al,7
    atohex_01:
	cmp ah,'9'
	jbe atohex_02
	add ah,7
    atohex_02:
	mov es:[di],ax
	dec si
	sub di,2
	cmp di,si
	jae atohex_loop
    atohex_end:
	mov dx,word ptr string+2
	mov ax,word ptr string
	ret
atohex endp

_TEXT	ENDS

	END
