3 ms·
More than one person noticed the addition of 6, and the significance that has to conversions between ASCII hex and binary, and came up with short (branchless) s
by userbinator 4y ago
More than one person noticed the addition of 6, and the significance that has to conversions between ASCII hex and binary, and came up with short (branchless) sequences for doing so using these and the other BCD instructions. This 6-byte sequence featuring DAA is apparently known as "Allison's Algorithm" online, although neither my references nor those I could find online lead me to the actual person of that name:
add al, 90h
daa
add al, 40h
daa
I believe it faded into obscurity once the shorter 5-byte sequence using DAS instead was discovered:
cmp al, 0ah
sbb al, 69h
das
- kens 4y agoThe algorithm was published by Dennis Allison in "A design philosophy for microcomputer architectures", Computer (Volume: 10, Issue: 2, February 1977), https://doi.org/10.1109/C-M.1977.217645 https://doi.org/10.1109/C-M.1977.217645 Curiously, the article discusses design goals for microcomputers at a high level. The hex to ASCII algorithm was a random example of the gap between compilers and machine code. Allison had done a bunch of work with Knuth on decimal arithmetic, so he probably had this example at his fingertips.
- Sniffnoy 4y agoNote that in Allison's Algorithm, that second ADD should actually be an ADC. (I say this both because that's what's in the original paper and because checking it myself that's what works -- it's needed to add the 1 for A through F, so you don't get @ through E instead. Didn't check the second one.)
- Sniffnoy 4y ago(Checking the second one, it's correct as written.)