Suppose AX=8FFE and BX= 0FFF
Now if we write
Cmp ax,bx
Now at this point what will happen is, source (bx) will be subtracted from destination (ax) and the appropriate flags will be updated. As computer represent each number in 2’s complement form so 8FFE is a 2’s complement of some number similarly 0FFF is 2’s complement of some number.
As in 2’s complement the subtraction is implemented by addition so we add these two numbers by converting them into binary.
8FFE----------> 1000 1111 1111 1110
0FFF----------> 0000 1111 1111 1111
--------------------------------
1001 1111 1111 1101
Now this is the result which is 9FFD in hex.
As you can see no overflow has occurred and the sign bit is 1 of the result.
Question: With this imagination that the sign flag should be set and overflow flag
Should remain 0, I checked this out in the debugger, but I found
Opposite of it
that is, sign flag remains 0 and the overflow flag is 1.
Now please tell me why
it happens?