6.4 O-flag

The O-flag represents “overflow”. This flag is even more fasinating than the sign flag.

The O-flag is set (becomes a 1) iff “the sign of the result makes no sense”. Let us cast that aside for now, and look at the definition of this flag in logic gate operations:

O = xn-1yn-1sn-1 + xn-1yn-1sn-1.

In this equation, the + symbol means disjunction.

xn-1yn-1sn-1 (the left hand side of the disjunction) is 1 iff the MSb of the numbers to be added are 1, whereas the MSb of the sum is 0. If the MSb is interpreted as the sign bit, this means that the addition of two negative values results in a non-negative value. This is why the sign of the result makes no sense. Let us use values in a 4-bit system for examples.

If we choose to interpret MSb as the sign of a number, 10002 = -C2(10002) = -10002 = -8. However, 10002 + 10002 = 00002 because of modulo add. This is essentially saying that -8 + (-8) = 0!

xn-1yn-1sn-1 (the right hand side of the disjunction) is 1 iff the MSb of the numbers to be added are 0, whereas the MSb of the sum is 1. This is the converse of the previous case. This happens when the sum of two non-negative values is negative.

Again, using a 4-bit system, we can set up an example:

7 + 7 = 01112 + 01112 = 11102 = -C2(11102) = -00102 = -2

The O-flag is set or cleared according to the logic equation for every add operation. It is up to a sign-sensitive instruction to interpret it after an add instruction executes.