.data
val1 BYTE 10h
val2 WORD 8000h
val3 DWORD 0FFFFh
val4 WORD 7FFFh
If val2 is incremented by 1 using the ADD instruction, what will be the values of the Carry and Sign flags?
If val4 is incremented by 1 using the ADD instruction, what will be the values of the Over- flow and Sign flags?
I answered both and got them both wrong. Why is the answer what it is?
Imagine it as a kind of analog clock. In a real clock the times "six fifty-five" (55) and "five to seven" (-5) are identical. It's just an issue of your definition, the clock itself doesn't know your definition and runs round and round and round... The same with the CPU. Look at the following "CPU-clock":
I've chosen a 4-bit-clock, but the principle is the same for every other group of bits (BYTE, WORD, DWORD etc.).
The carry flag will be set after the clock has jumped from 15 to 0. It is in this case a flag for unsigned overflow.
The overflow flag will be set after the clock has jumped from 7 to -8. It flags a signed overflow.
The sign flag flags a value which can be interpreted as a negative number.
The behavior of the flags is a little bit different, if you count downwards: