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
DAA.
-
AAA(ASCII Adjust After Addition) should be used after a one-byteADDinstruction whose destination was theALregister: by means of examining the value in the low nibble ofALand also the auxiliary carry flagAF, 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 doingADD/AAAon the low digits, then doingADC/AAAon each subsequent digit. -
AAS(ASCII Adjust AL After Subtraction) works similarly toAAA, but is for use afterSUBinstructions rather thanADD. -
AAM(ASCII Adjust AX After Multiply) is for use after you have multiplied two decimal digits together and left the result inAL: it dividesALby ten and stores the quotient inAH, leaving the remainder inAL. The divisor 10 can be changed by specifying an operand to the instruction: a particularly handy use of this isAAM 16, causing the two nibbles inALto be separated intoAHandAL. -
AAD(ASCII Adjust AX Before Division) performs the inverse operation toAAM: it multipliesAHby ten, adds it toAL, and setsAHto zero. Again, the multiplier 10 can be changed.