I am writing a game for the ZX Spectrum using the z80 and have a bit of a problem. I manipulated a routine to convert the number contained in register "a" into the hexadecimal value contained in "de". I'm not sure how to convert the other path, EG is passed in hexadecimal to de and converts it to the decimal number contained in "a".
Note. The following procedure converts the input into ascii values that represent values from 0 to F. EG, if a = 255, then d = 70 and e = 70, since "F" is the value of ascii 70.
NumToHex ld c, a ; a = number to convert
call Num1
ld d, a
ld a, c
call Num2
ld e, a
ret ; return with hex number in de
Num1 rra
rra
rra
rra
Num2 or $F0
daa
add a, $A0
adc a, $40 ; Ascii hex at this point (0 to F)
ret
Can someone advise a solution for working in the opposite direction or suggest a better solution?