Condition Flags

Four condition flags

  1. Carry flag - C
  2. Overflow flag - V
  3. Zero flag - Z
  4. Negative flag - N

These are assigned new values every time an instruction is performed

Carry Flag - C

 It is said that a carry has occured when the addition of the filnal column would result in the need for an extra column to fully represent the number. The carry flag is assigned a value of 1 when carry has occured, otherwise it is assigned the value 0

Zero Flag - Z

Assigned a value of 1 when the operation results in a value of 0, representing true. Otherwise, the flag is a assigned the value 0, representing false.

Unsigned and Signed Interpretations of Binary Numbers

A computer must represent everything using 1's and 0's. A minus sign cannot be put in front of the binary number in a computer. In order to represent both positive and negative numbers, a different set of weights is used. To represent negative numbers, the weight of the leftmost bit is changed to a negative number.

For an 8-bit binary number, the binary number 10011010 represented the decimal value -102 (-128 + 16 + 8 + 2 = -102)

It is easy to tell if a number is positive or negative by looking at the leftmost bit. If the bit is 1, the number must be negative.

Using the unsigned intreptation, an 8-bit binary number can represent a decimal value in the range of 0 to 255. For the signed interpretation, an 8-bit number can represent a decimal value in the range -128 to 127.

Overflow Flag - V

When two numbers are added, whether or not the result is within the valid range must be determined. If the result is not within the valid range, it is said that overflow has occured, and the overflow flag is assigned the value 1. Otherwise V is assigned the value 0.

It is important to remember the following rule which is used to decide whether overflow has occured when two signed numbers have been added.

If the two numbers are positive and the result is negative, overflow has occured.
If the two numbers are negative and the result is positive, overflow has occured.
If one number is positive and the other negative, it is not possible for there to be overflow.

Negative Flag - N

Assigned a value of 1 when the result using signed interpretation is negative. Otherwise assigned a value of 0.