4.1.6 · D1Computer Architecture (Deep)

Foundations — ALU — operations, flags (zero, carry, overflow, negative)

1,859 words8 min readBack to topic

Before you can understand why the ALU raises the Carry flag but not the Overflow flag (or vice-versa), you have to be fluent in the raw vocabulary the parent note throws around: bits, MSB, , "", , "mod", and the idea of interpreting the same bits two different ways. We define each below, in the order they build on each other.


1. A bit — the atom

The picture: imagine one lamp. Off means , on means . That's a bit.

Why the topic needs it: the ALU's operands, its result, and every flag are all bits. If you can't picture one lamp, you can't picture the eight lamps that hold an 8-bit number.


2. A binary number and place value

Line up several lamps in a row. The parent note works with 8 bits (eight lamps). Reading them as a number requires place value.

Figure — ALU — operations, flags (zero, carry, overflow, negative)

Why the topic needs it: every operand (, ) and result () in the parent note is written as 8 lamps; place value is how you translate those lamps into the numbers , , , etc.


3. , and the notation

Why does keep appearing? Because with lamps, each lamp independently ON/OFF, the number of different patterns you can make is .

The picture: a car odometer with wheels. It shows distinct readings before it rolls back to zero.


4. MSB and LSB — the most/least important lamp

The picture: in a row of 8 lamps, the far-left lamp (, worth ) is the MSB; the far-right lamp (, worth ) is the LSB.

Why the topic needs it: the Negative flag is literally the MSB (), and carry/overflow are all about what happens at the MSB end of the row. Every flag lives near the MSB.


5. Signed vs unsigned — reading the SAME lamps two ways

This is the deepest idea on the page, and the whole reason there are two "too big" flags (Carry and Overflow).

Figure — ALU — operations, flags (zero, carry, overflow, negative)

Why the topic needs it: Carry watches the unsigned interpretation ("did we pass ?"); Overflow watches the signed interpretation ("did we leave ?"). Two readings ⇒ two flags. See Signed vs Unsigned Comparison Instructions for how branches use each.


6. The symbol — bitwise NOT (invert)

Why the topic needs it: two's complement negation is "invert and add one," . The parent's subtraction trick leans entirely on this symbol.


7. "mod " — the wrap-around

The picture: the odometer again. When an 8-wheel odometer passes it doesn't show — it rolls back to . That rollover is "mod ."

Why the topic needs it: every ALU add/subtract silently happens "mod " because only lamps survive. The flags exist precisely to report the information that the mod threw away.


8. — exclusive-OR (XOR)

0 0 0
0 1 1
1 0 1
1 1 0

Why the topic needs it: the Overflow flag is — it fires exactly when the carry into the sign bit differs from the carry out of it. XOR is the perfect "are these two carries different?" detector.


9. Carry-in and carry-out — how lamps talk to their neighbours

Figure — ALU — operations, flags (zero, carry, overflow, negative)

The picture: grade-school column addition, but each column holds one bit. A carry ripples left, column by column — this is the Full Adder and Ripple-Carry Adder.

Why the topic needs it: the Carry flag is the carry-out of the very last (MSB) column, . The Overflow flag compares with (the carry into the MSB). Both flags are just wires tapping these carry signals.


10. "Combinational" — no memory

Contrast this with Combinational vs Sequential Logic: sequential circuits remember. The ALU itself is combinational; the flags get stored afterward in the Status / Flags Register (PSR / EFLAGS) so later instructions (branches) can read them.

Why the topic needs it: the parent note stresses "no memory" so you understand the ALU is a pure function — flags are computed fresh, then latched elsewhere.


How it all feeds the topic

Bit: 0 or 1

Row of n lamps

Place value: weights 1 2 4 8

n and 2 to the n patterns

MSB and LSB positions

Signed vs Unsigned reading

NOT: flip bits

Twos complement negate

mod 2 to the n wraparound

Carry flag

Carry in and Carry out

XOR of two carries

Overflow flag

Negative flag equals MSB

Subtraction as addition

ALU flags and operations

This map is the skeleton of the parent ALU topic: everything on the left must be solid before the flags on the right make sense. Flags then flow into Condition Codes and Conditional Branches.


Equipment checklist

Test yourself — cover the right side of each line and try to answer:

What is a bit?
A single slot holding exactly or ; picture one lamp OFF/ON.
In , what is the value?
(weights and ).
Why does appear everywhere?
With bits there are distinct patterns.
Which bit is the MSB in an 8-bit number?
The leftmost bit , weight (or signed).
Same lamps : unsigned value and signed value?
unsigned, signed.
What does do?
Inverts every bit ().
Compute .
.
What does "mod " mean physically?
Odometer rollover — discard everything above the top lamp.
When is ?
When and differ.
Carry-in vs carry-out of a column?
Carry-in arrives from the right; carry-out leaves to the left.
The Negative flag equals what?
The MSB of the result, .
What does "combinational" mean?
Output depends only on current inputs — no stored memory.