AAS is the subtraction counterpart of AAA. After SUB (or SBB) of one unpacked BCD digit from another, with the result in AL, it brings AL back to a digit 0–9 and takes a decimal borrow from AH when one was needed.
Exactly what it does
If the low four bits of AL are greater than 9, or AF is 1, then AAS subtracts 6 from AL, subtracts 1 from AH, and sets AF and CF to 1. Otherwise it clears AF and CF. In both cases it then clears the upper four bits of AL. OF, SF, ZF and PF are undefined.
A borrow shows up in AF: subtracting a larger digit from a smaller one borrows across bit 4, and the low four bits then hold 16 plus the smaller digit minus the larger (2 − 5 leaves Dh, 13). Taking 6 more away leaves 7, the right digit for ten plus 2, minus 5.
MOV AX, 0402h ; unpacked 42: AH = 4, AL = 2SUB AL, 5 ; AL = FDh, a borrow (AF = 1)AAS ; AL = 7, AH = 3: unpacked 37OR AX, 3030h ; both digits -> charactersMOV BX, AXMOV DL, BHMOV AH, 02h ; DOS: print DLINT 21hMOV DL, BLMOV AH, 02hINT 21h
Multi-digit differences
For long numbers held as digit strings, go from the last digit to the first: SBB the two digits (CF holds the borrow from the previous column), AAS, store AL, repeat. Clear CF with CLC before the first column. When the final CF is 1 the second number was larger and the stored digits are the ten's complement of the difference.
Pitfalls
AAS corrects AL only. It is for unpacked digits; for two digits packed in a byte use DAS. Remember that AAS changes AH, which may be holding something else.
Later CPUs
Unchanged in 16- and 32-bit code; not available in 64-bit mode.