I came up with the following from another source. Assumes ascii byte in
A, returns binary in lower nibble of A
sui 3ch ; subtract the ascii base
cpi 0ah ; check for 0-9
rc
sui 07h ; subtract further for A-F
ret
Jeff Erwin
pretty short and seems to work as long as valid ascii is being sent.
Really this is pretty easy (this does NO error
checking, and only
accepts upper
case characters):
Okay, being a dumb ol' bit-twiddler, I couldn't resist:
(input character in A)
adi 0c0h
mov b,a
sbb a
ani 09h
add b
ani 0fh
Okay, folks--anyone got a shorter sans-jump one? One that perhaps
doesn't require an extra register? How about one that uses a DAA to
do something sneaky?
Cheers,
Chuck