Different CPUs have different things, including flags.

But for a MIP, we have 4:

  • Overflow
  • Result is zero
  • Result is negative

Overflow

  • For unsigned numbers, if , then there is overflow
  • For signed numbers (either A or B are negative):
    • For G = A + B, we have overflow when
      1. A and B have the same sign
      2. G has opposite sign
    • For G = A - B, we have overflow when
      1. A and B have different signs
      2. G has the same sign as B
      • E.g: A = -2 and B = 15. A - B = -17. B is negative; -17 is negative. We have overflow!
    • For G = A + B and A, B have different signs
      • It can never overflow!

Zero Flag (not on the slides)

=

  • Checks if any number is 1. If it is, it’s not zero!