Assembly - Carry Flag VS Overflow Flag


Answer :

Overflow occurs when the result of adding two positive numbers is negative or the result of adding two negative numbers is positive. For instance: +127+1=?

+127=0111 1111   +1=0000 0001      ---------      1000 0000  

As we look at the sign bits of the two operands and the sign bit of the result, we find out that Overflow occurred and the answer is incorrect.


In unsigned arithmetic, you have added 0xFB to 0x84, i.e. 251 + 132, which indeed is larger than 8-bit, and so the carry flag is set.

In the second case, you are adding +127 to 1, which indeed exceeds a signed 8-bit range, and so the overflow flag is set.


Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?