B.4.1. `AAA', `AAS', `AAM', `AAD': ASCII Adjustments
----------------------------------------------------
AAA ; 37 [8086]
AAS ; 3F [8086]
AAD ; D5 0A [8086]
AAD imm ; D5 ib [8086]
AAM ; D4 0A [8086]
AAM imm ; D4 ib [8086]
These instructions are used in conjunction with the add, subtract,
multiply and divide instructions to perform binary-coded decimal
arithmetic in _unpacked_ (one BCD digit per byte - easy to translate to
and from `ASCII', hence the instruction names) form. There are also
packed BCD instructions `DAA' and `DAS': see *Note Section B.4.57::.
* `AAA' (ASCII Adjust After Addition) should be used after a one-byte
`ADD' instruction whose destination was the `AL' register: by
means of examining the value in the low nibble of `AL' and also the
auxiliary carry flag `AF', it determines whether the addition has
overflowed, and adjusts it (and sets the carry flag) if so. You
can add long BCD strings together by doing `ADD'/`AAA' on the low
digits, then doing `ADC'/`AAA' on each subsequent digit.
* `AAS' (ASCII Adjust AL After Subtraction) works similarly to
`AAA', but is for use after `SUB' instructions rather than `ADD'.
* `AAM' (ASCII Adjust AX After Multiply) is for use after you have
multiplied two decimal digits together and left the result in
`AL': it divides `AL' by ten and stores the quotient in `AH',
leaving the remainder in `AL'. The divisor 10 can be changed by
specifying an operand to the instruction: a particularly handy use
of this is `AAM 16', causing the two nibbles in `AL' to be
separated into `AH' and `AL'.
* `AAD' (ASCII Adjust AX Before Division) performs the inverse
operation to `AAM': it multiplies `AH' by ten, adds it to `AL', and
sets `AH' to zero. Again, the multiplier 10 can be changed.