;showbyte
;
;make a callable Procedure which takes one argument in the dl
;and returns output in the DX
;
;input: byte size number
;output: two ASCII chars which represent the input byte as 2-digit Hexadecimal number
;
;we'll print our conversions to screen using DOS 'write char' function 02
;
segment stack stack
resb 100h
segment data
crlf db 0Dh,0Ah,'$'
segment code
..start:
mov ax, data
mov ds, ax
                ;convert the value 23h into it's ASCII representation: ASCII '2' (32h) and '3' (33h)
mov dl, 23h
call showbyte
mov ah, 2                 ;print char function
xchg dh, dl
int 21h
                ;ah is still 2
xchg dh, dl
int 21h
mov ah, 9
mov dx, crlf
int 21h
                ;convert the value E7h into it's ASCII representation: ASCII 'E' (45h) and '7' (37h)
mov dl, 0E7h
call showbyte
mov ah, 2
xchg dh, dl
int 21h
                ;ah is still 2
xchg dh, dl
int 21h
mov ah, 4Ch
mov al, 0
int 21h
showbyte:
                ;strategy: copy dl into dh.
                ;in DH, translate upper 4 bits. in DL translate lower 4 bits
mov dh, dl
mov cl, 4
shr dh, cl                 ;Bit Shift Right by amount specified in cl.
add dh, 30h                 ;sets number equivalent to ascii values 0-9
cmp dh, 39h
jna sb_cont1                 ;jump if not above- if ascii is wthin range of 0-9, work on next number in DL
add dh, 7                 ;otherwise, number is above 9 and needs to be represented be Alfa char A-F
sb_cont1:
and dl, 00001111b                 ;clears top 4 bits
add dl, 30h
cmp dl, 39h
jna sb_cont2
add dl, 7
sb_cont2:
ret