home *** CD-ROM | disk | FTP | other *** search
- ;
- ; HEXASC --- converts a binary 16-bit number into
- ; a "hexadecimal" ASCII string.
- ;
- ; Copyright (C) 1984 Ray Duncan
- ;
- ; Call with AX = value to convert
- ; DS:BX = address to store 4-character string
- ;
- ; Returns AX, BX destroyed, other registers preserved
- ;
- hexasc proc near
-
- push cx ; save registers
- push dx
- mov dx,4 ; initialize character counter
-
- hexasc1:
- mov cx,4 ; isolate next four bits
- rol ax,cl
- mov cx,ax
- and cx,0fh
- add cx,'0' ; convert to ASCII
- cmp cx,'9' ; is it 0-9?
- jbe hexasc2 ; yes, jump
- ; add fudge factor for A-F
- add cx,'A'-'9'-1
-
- hexasc2: ; store this character
- mov [bx],cl
- inc bx ; bump string pointer
-
- dec dx ; count characters converted
- jnz hexasc1 ; loop, not four yet
-
- pop dx ; restore registers
- pop cx
- ret ; back to caller
-
- hexasc endp
- ;