1
votes

I know that when performing an 8-bit binary addition, the auxiliary flag is set to 1 if there is a carry from 3rd bit to 4th bit; but what about the addition of 2 16-bit numbers? i can't see any clear answer on the web.

I'm studying intel 8086 microprocessor...

For example, when i add these 2 numbers, 0x30a2 and 0xf1ac

0011 0000 1010 0010 + 1111 0001 1010 1100

CF=1
ZF=0
PF=1
SF=0
OF=1
AF=? 

I'm not sure where to check it

3
which cpu? not all behave the same usually the 3rd to 4th bit carry flag is for BCD support.BevynQ
Th AF flag still only applies to carry out of the lowest nibble (lowest 4 bits). In your example the lowest nibble is 0010+1100 . Clearly there is no carry out of bit 3 so AF =0.Michael Petch
Weather vanes answer says "The high or low nibble refers to the LOW order BYTE of a 16-bit value." . So the nibble being referred to is in the least significant byte. Nibbles are always 4 bits (not 8 bits). It basically says that no matter how many bits your register has (also applies to 32-bit) the AF flag will always be set based on carry out of the lowest nibble in the low order (least significant byte)Michael Petch
What is it you are really trying to accomplish? Are you trying to do BCD arithmetic? If not, the AF flag is not very useful.Michael Petch
I would help everyone's understanding if you stopped referring to bit 3 as the 3rd bit and to bit 4 as the 4th bit. The only good wording is: bit 3 is 4th bit and bit 4 is 5th bit.Fifoernik

3 Answers

4
votes

From "Programming the 8086/8088" by James W. Coffron:

AF auxiliary carry flag. If this flag is set, there has been a carry of the low nibble to the high nibble or a borrow from the high nibble to the low. The high or low nibble refers to the low order byte of a 16-bit value.

In my day we would write a short piece of code to observe the processor behaviour. You could check it out by adding or subtracting two 16-bit numbers, followed by a pushf and pop ax to examine the status flags at your pleasure.

EDIT.

(Another way to get the flags is with LAHF which loads 5 bits of AH with flags, AF going to bit 4.)

So AF represents the carry out from bit 3 to bit 4, whatever the size of the operands.

Note that there are no branch instructions dependent on AF. It is used internally by the DAA instruction to do a decimal adjustment immediately after an ADD instruction, typically with AL.

2
votes

On the 8086 the adjust flag (bit 4) was set when there was a carry from the 3rd to 4th bit or a borrow from the 4th to 3rd bit this is for BCD operation support.

BCD operationson the 8086 are 8 bit only and the BCD adjust operations only operate on the AL register.

For a 16 bit operation I would expect it to behave the same as if it was an 8 bit operation.

The carry flag (bit 0) is based on whether the operation is 8 or 16bit. If it is 16 bit then it will carry if the result > 65535. If it is 8 bit then it will carry if the result > 255.

0
votes

the "posititon" of the carry flag depends on the operators instruction, it will always be the highest bit

e.g. add ax,bx : since the operants are 16 bit, the carry will represent the carry of the addition of the 16th bits even if you add ax ( with a value of 3) and 9 (these values will be treated as 0000000000000011 and 0000000000000101)