Converting ASCII to Hex (was: 1st stage loader for IMSAI - need ascii to binary conversion)

Jim Leonard trixter at
Mon Feb 25 21:29:05 CST 2008

Chuck Guzis wrote:
> 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?

Although it's the other way round, this is one of my top five favorite 
gems of all time:

; input:
;   al = single hex digit
; output:
;   al = single ASCII digit
; destroys:
;   flags

         cmp     al,10           ; if x < 10, set CF = 1
         sbb     al,69h          ; 0-9: 96h .. 9Fh,  A-F: A1h..A6h
         das                     ; 0-9: subtr. 66h -> 30h-39h,
                                 ; A-F: subtr. 60h -> 41h..46h

Using the above as a basis for ascii-to-hex is left as an exercise for 
Chuc^H^H^H^Hthe reader.
Jim Leonard (trixter at  
Help our electronic games project: 
Or check out some trippy MindCandy at
A child borne of the home computer wars:

More information about the cctech mailing list