Reputation: 85
The auxiliary flag becomes set when the lower nibble produces a carry to the higher order nibble. For example:
1001 9
1001 9
---- ----
1 0010 18
In this case the axillary carry is set.
I also heard that this carry is used to add 0110 to the lower order nibble during BCD addition in order to get the correct BCD answer.
But consider this case
1001 9
0011 3
---- ---
1100 12
In this case the carry is not generated from this nibble, the auxiliary carry is not set,but the answer is not the correct BCD addition. Then what prompts the processor to correct the answer and get the correct BCD answer?
Upvotes: 2
Views: 498
Reputation: 25874
You have to do it manually using DAA
or AAA
. This will adjust the current nibble if > 9 and add 1 to the higher nibble.
Upvotes: 1
Reputation: 64933
The rest of the semantics of DAA
(or AAA
). In full, they are (for DAA
):
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 (Carry from AL ← AL + 6);
AF ← 1;
ELSE
AF ← 0;
FI;
IF ((old_AL > 99H) or (old_CF = 1))
THEN
AL ← AL + 60H;
CF ← 1;
ELSE
CF ← 0;
FI;
FI;
So you see, it's not just AF that matters, it also checks whether the digit is > 9.
Upvotes: 3