Skip to content
Tactiverge
  1. Stage 1
  2. Stage 2
  3. Stage 3
  4. Stage 4
  5. Stage 5
  6. Stage 6
  7. Stage 7
  8. Stage 8
  9. Stage 9
  10. Stage 10
  11. Stage 11 (this one)
  12. Stage 12
  13. Stage 13
  14. Stage 14
  15. Stage 15

Explanation

The ALU computes every operation at once (sum, difference, AND, OR, XOR, NOT) and a mux driven by the operation code picks which result leaves. It also sets flags: Z (result zero), C (carry out, or borrow on subtract), N (top bit set, negative if signed) and V (signed overflow).

Flags are how a program makes decisions: subtract two numbers and look at Z to see whether they were equal, or at C to see which was bigger.

Operands in, result and flags out

A = 5

B = 7

SUB: A − B, computed as A + NOT B + 1.

Y = 254 (signed -2, 0xFE)

1
1
1
1
1
1
1
0
  • Z = 0
  • C = 1
  • N = 1
  • V = 0

Z zero · C carry (ADD) or borrow (SUB) · N top bit set · V signed overflow

SUB gives 254; flags Z 0 C 1 N 1 V 0

Check yourself

Marked instantly in your browser. Use the interactive above to work it out.

  1. 1. The ALU computes 5 − 7 on bytes. What value (0–255) does it output?
  2. 2. After SUB, which flag tells you the two numbers were equal?