das
Decimal Adjust After Subtraction
Adjusts AL after subtraction for packed BCD.
Details
Adjusts AL after subtraction of two packed BCD values. If the lower nibble exceeds 9 or AF is set, subtracts 6 from AL; if the upper nibble then exceeds 9 or CF is set, subtracts 0x60 from AL. Sets CF and AF as needed; OF is undefined; SF, ZF, PF are computed on the result.
Pseudocode Operation
old_AL ← AL;
if ((AL & 0x0F) > 9) || (AF == 1) {
AL ← AL - 6;
AF ← 1;
} else {
AF ← 0;
}
if (old_AL > 0x99) || (CF == 1) {
AL ← AL - 0x60;
CF ← 1;
} else {
CF ← 0;
}
ZF ← (AL == 0);
SF ← (AL[7] == 1);
PF ← parity(AL);
Example
Encoding
Operands
Reference (Intel® SDM)
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| 2F | DAS | ZO | Invalid Valid | Decimal adjust AL after subtraction. |
Description
Operation
IF 64-Bit Mode THEN #UD; ELSE old_AL := AL; old_CF := CF; CF := 0; IF (((AL AND 0FH) > 9) or AF = 1) THEN AL := AL - 6; CF := old_CF or (Borrow from AL := AL − 6); AF := 1; ELSE AF := 0; FI; IF ((old_AL > 99H) or (old_CF = 1)) THEN AL := AL − 60H; CF := 1; FI; FI; Example SUB AL, BL Before: AL = 35H, BL = 47H, EFLAGS(OSZAPC) = XXXXXX After: AL = EEH, BL = 47H, EFLAGS(0SZAPC) = 010111 DAA Before: AL = EEH, BL = 47H, EFLAGS(OSZAPC) = 010111 After: AL = 88H, BL = 47H, EFLAGS(0SZAPC) = X10111
Flags Affected
The CF and AF flags are set if the adjustment of the value results in a decimal borrow in either digit of the result (see the “Operation” section above). The SF, ZF, and PF flags are set according to the result. The OF flag is undefined. DAS—Decimal Adjust AL After Subtraction Vol. 2A 3-260