Decimal Arithmetic
Businesses do not care about the speed of binary computations because
the computer can be too precise, they only want dollars and cents, nothing
else. To meet this, early computers gave them a new data type and new instructions
to deal with it: The Binary Coded Decimal.
There are two additional instructions that go along with the new data types,
DAA or Decimal Adjust After Addition:
"Adjusts the result of an addition to a packed BCD number (less than 100 decimal).
The previous addition should place its 8-bit sum in AL. DAA converts this binary sum
to packed BCD format with the least significant decimal digit in the lower
four bits and the most significant digit in the upper four bits. If the sum is greater
than 99h after the adjustment, the carry and auxiliary carry flags are set. Otherwise,
the carry and auxiliary carry flags are cleared." Microsoft MASM Reference
There is also a Decimal Adjust After Subtraction:
"Adjusts the result of a subtraction to a packed BCD number
(less than 100 decimal). The previous subtraction should place its 8-bit
result in AL. DAS converts this binary sum to packed BCD format with the least
significant decimal digit in the lower four bits and the most significant digit
in the upper four bits. If the sum is greater than 99h after the adjustment, the carry
and auxiliary carry flags are set. Otherwise, the carry and auxiliary carry flags
are cleared." Microsoft MASM Reference
It is easier to understand a picture of trying to add the decimal numbers 56 and 35.
We know that is 91 in decimal. In the BCD format, 6 plus 5 = 11 or 0Bh. That is
too big for one decimal position, so we have to add a carry to the result of 5 + 3.
UMBC |
CSEE