|
|
|
|
|
by adrian_b
38 days ago
|
|
Intel 8080 already had DAA, so it could add BCD numbers. Because there was no BCD subtraction, that had to be done by an indirect method, e.g. by doing a nines' complement before a BCD addition. Zilog Z80 improved this, so that on it DAA could also be used after a subtraction, when it would correctly adjust the result for implementing BCD subtraction. This was one of the Z80 improvements that were considered important at the time of its launch. While I have never considered worthwhile to do BCD arithmetic instead of converting the decimal numbers to binary numbers, the DAA instruction on all Intel 8080 successors, including on IBM PC compatible computers, was very convenient for converting binary numbers to their ASCII character string hexadecimal representation, for printing or display purposes (because the decimal adjusting happens to add the correct ASCII offset between '0' ... '9' and 'A' ... 'F', so the conversion to ASCII can be done branchless). |
|
On the Z80 and 8086, the code can be made one byte shorter by taking advantage of adjust-after-subtraction, which the 8080 didn't have (and on 6502 worked differently):