What I commented maybe not precise enough, though. I mistake CARRY for OVERFLOW.
-
So explain it little further
Your operation is:
01101 (binary) + 11110 (binary) = 01011 (binary)
-
if signed (CORRECT RESULT):
13 (decimal) + -2 (decimal) = 11 (decimal)
if unsigned (UNDESIRED RESULT):
13 (decimal) + 30 (decimal) = 11 (decimal)
-
There are two things in a binary arithmetic operation called separately OVERFLOW and CARRY.
For addition operation, The CARRY flag is set if the
addition of two numbers causes a carry out of the most significant
(leftmost) bits added.
example:
1111 + 0001 = 0000 (carry flag is turned on)
0111 + 0001 = 1000 (carry flag is turned off)
For subtraction operation, The CARRY flag is set if the
the subtraction of two numbers requires a borrow into the most significant (leftmost)
bits subtracted.
example:
0000 - 0001 = 1111 (carry flag is turned on)
1000 - 0001 = 0111 (carry flag is turned off)
For addition operation, the OVERFLOW flag is set if the
addition of two numbers with the same most significant bit (both 0 or
both 1) and the result produced a binary with a different most
significant bit.
example:
0100 + 0100 = 1000 (overflow flag is turned on)
0100 + 0001 = 0101 (overflow flag is turned off)
-
Note that:
In unsigned arithmetic, watch the carry flag to detect errors.
In signed arithmetic, the carry flag tells you nothing interesting.
-
In signed arithmetic, watch the overflow flag to detect errors.
In unsigned arithmetic, the overflow flag tells you nothing interesting.
-
check error in adding unsigned binaries in assembly language
ADD BX, AX
//check carry here
check error in subtracting unsigned binaries in assembly language
SUB BX, AX
//check carry here
check error in adding signed binaries in assembly language
ADD BX, AX
//check overflow here
check error in subtracting signed binaries in assembly language
SUB BX, AX
//check overflow here
See this for detail of the flag sets in ADD/SUB
carry/overflow & subtraction in x86