aas
ASCII Adjust After Subtraction
AAS
Adjusts AL after subtraction for unpacked BCD.
Details
Adjusts the value in AL after a subtraction operation to make it a valid unpacked BCD digit (0–9 in the lower nibble). If the lower nibble of AL is greater than 9 or the auxiliary carry flag is set, AL is decremented by 6 and AH is decremented by 1; otherwise no adjustment occurs. Sets or clears AF and CF based on whether an adjustment was made; other flags are undefined.
Pseudocode Operation
if ((AL & 0x0F) > 9) || (AF == 1) {
AL ← AL - 6;
AH ← AH - 1;
AF ← 1;
CF ← 1;
} else {
AF ← 0;
CF ← 0;
}
AL ← AL & 0x0F;
Example
AAS
Encoding
Binary Layout
3F
+0
Operands
Reference (Intel® SDM)
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| 3F | AAS | ZO | Invalid Valid | ASCII adjust AL after subtraction. |
Description
Adjusts the result of the subtraction of two unpacked BCD values to create a unpacked BCD result. The AL register is the implied source and destination operand for this instruction. The AAS instruction is only useful when it follows a SUB instruction that subtracts (binary subtraction) one unpacked BCD value from another and stores a byte result in the AL register. The AAA instruction then adjusts the contents of the AL register to contain the correct 1digit unpacked BCD result.
If the subtraction produced a decimal carry, the AH register decrements by 1, and the CF and AF flags are set. If no decimal carry occurred, the CF and AF flags are cleared, and the AH register is unchanged. In either case, the AL register is left with its top four bits set to 0.
This instruction executes as described in compatibility mode and legacy mode. It is not valid in 64-bit mode.
Operation
IF 64-bit mode THEN #UD; ELSE IF ((AL AND 0FH) > 9) or (AF = 1) THEN AX := AX – 6; AH := AH – 1; AF := 1; CF := 1; AL := AL AND 0FH; ELSE CF := 0; AF := 0; AL := AL AND 0FH; FI; FI;
Flags Affected
The AF and CF flags are set to 1 if there is a decimal borrow; otherwise, they are cleared to 0. The OF, SF, ZF, and PF flags are undefined.
Exceptions
Protected Mode Exceptions
#UD If the LOCK prefix is used.
Real-Address Mode Exceptions
Same exceptions as protected mode.
Virtual-8086 Mode Exceptions
Same exceptions as protected mode.
AAS—ASCII Adjust AL After Subtraction Vol. 2A 3-7
Compatibility Mode Exceptions
Same exceptions as protected mode.
64-Bit Mode Exceptions
#UD If in 64-bit mode.
AAS—ASCII Adjust AL After Subtraction Vol. 2A 3-8