4 bit (and 8 bit) to ASCII Hex
4bit-ASCIIHex: ;***** UNTESTED!!!
mov temp, w ;save the value
mov w, #-09
add w, temp ;compare temp with 9
mov w, #'A' ;assume it will be more (no change to compare flags)
snc ;if it was less
mov w, #'0' ;correct the offset
add w, temp ;add the offset to the value
ret
See:
Compareing values in the "X < Y" section "fr < n" subsection for an explination of how the comparison works. For 8 bits you have to call that twice:
8bit-ASCIIHex: ;***** UNTESTED!!!
mov w, <>byte ;w is byte with upper and lower nibbles reversed
and w, #15 ;mask off the upper (was lower) 4 bits
call 4bit-ASCIIHex ;convert that nibble to ASCII Hex
call Output ;and send it off to where ever
mov w, byte ;now get the actual value
and w, #15 ;mask off the upper (really) 4 bits
call 4bit-ASCIIHex ;convert this nibble to ASCII Hex
call Output ;and send it off.