Reputation: 1431
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?
Upvotes: 1
Views: 1127
Reputation: 60065
i think you did subtraction incorrectly. My result is:
8FFE----------> 1000 1111 1111 1110
0FFF----------> 0000 1111 1111 1111
----------------------------------
7FFF----------> 0111 1111 1111 1111
what happened is that operation borrowed from sign bit only. This means OF flag should be set. Read here about assembly CF(Carry) and OF(Overflow) flag, http://en.wikipedia.org/wiki/Carry_flag, http://en.wikipedia.org/wiki/Overflow_flag. It means that is it was signed operation it is incorrect. if it was unsigned then fine.
Upvotes: 2