问题
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
回答1:
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:
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 operations
on 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.
回答3:
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)
来源:https://stackoverflow.com/questions/36492553/how-to-set-auxiliary-flag-for-16bits-binary-addition