Maccey21
asked on
A simple hex dump
I am having increased trouble in converting a simple string from ascii to hex format and outputting to screen.
I need some simple code to show me how it is done. I do have an idea of how to do it but cant put code on to it.
I need some simple code to show me how it is done. I do have an idea of how to do it but cant put code on to it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
First take a charcter form your buffer
something like mov al,[si] ; where si is a pointer to your buffer.
This assumes that al contains ascii "0 - 9" "A - F' but also works with 'a - f' lower case.
add al,40h
cbw
and ah,09h
add al,ah
and al,0Fh
al now has the hex nibble (4 bits) ie. 0 to 0fh
you can shift it left 4 places to make it the high nibble
and to go back the other way assume al has a value between 0 and 0fh ( 4 bits )
cmp al,10
sbb al,69h
das
al now has '0 - 9 ... A - F' ascii
put this byte for byte in your output buffer. and make it a string. With dos INT 21h subfunction 9, use dx reg. as a pointer to a ascii string. the last character in the string must be a '$'.
something like mov al,[si] ; where si is a pointer to your buffer.
This assumes that al contains ascii "0 - 9" "A - F' but also works with 'a - f' lower case.
add al,40h
cbw
and ah,09h
add al,ah
and al,0Fh
al now has the hex nibble (4 bits) ie. 0 to 0fh
you can shift it left 4 places to make it the high nibble
and to go back the other way assume al has a value between 0 and 0fh ( 4 bits )
cmp al,10
sbb al,69h
das
al now has '0 - 9 ... A - F' ascii
put this byte for byte in your output buffer. and make it a string. With dos INT 21h subfunction 9, use dx reg. as a pointer to a ascii string. the last character in the string must be a '$'.
Mike