…or: The assembler code snippet of the week
add al,90h
daa
adc al,40h
daa
Can anyone tell me without cheating what this code does?
Show solution ▼
The code converts a nibble (half byte, i.e. values from 0 to 15) in the al
register into the ASCII value of the respective hexadecimal digit (0..9A..F) – the trick is that it does so without comparison and jump or conditional commands which would be needed if you do it the more obvious method “add 30h (ASCII code of 0); if greater than 9, also add the difference of the ASCII codes for A and 9 (since there’s a gap)”.
Well, I came across it again today…
Blinkfeuer1 2009-05-15 at 0:10 14 Comments
quote
Wieso Hexerei? Ich nenn das klare Kante.
Glückauf!
Dein Münte.
cimddwc 2009-05-15 at 12:35 6316 Comments
quote
Mir fällt keine gscheite Antwort ein, deswegen:
rolak2 2009-05-17 at 9:36 747 Comments
quote
Daß ich diesen guten alten nibble=>HexChar-Hack nochmal wiedersehe einer aus der Standardmacrosammlung…
Solche Magie kann ruhig öfter mal kommen, kein Problem, keine Angst.
cimddwc 2009-05-17 at 14:28 6316 Comments
quote
Da muss ich mal sehen, was sich sonst noch in meinen Codes verbirgt…