3.3.13 · D4Combinational Circuits

Exercises — ALU design fundamentals

2,366 words11 min readBack to topic

Before we start, one shared reference figure — the 4-bit adder/subtractor every problem leans on.

Figure — ALU design fundamentals

L1 — Recognition

Goal: recall a definition and read it straight off the circuit — no computation chains.

Recall Solution 1.1

The multiplexer (Multiplexer). Every operation (add, subtract, AND, OR, …) computes in parallel and all results arrive at the MUX at once. The select lines act like an address: for select bits the MUX chooses one of inputs to route to . Nothing is "computed" by the MUX — it only steers an already-finished result. (See the amber MUX box in the figure.)

Recall Solution 1.2

Combinational means the output depends only on the current inputs — there is no stored past. Because there is nothing to "remember", there is nothing to update on a clock edge, so the ALU needs no clock. State (registers) lives outside the ALU in the Datapath and Control Unit.

Recall Solution 1.3
  • — result is exactly zero (all result bits are 0).
  • unsigned carry out of the MSB.
  • — the sign bit; means negative in two's complement.
  • signed overflow (the sign bit got corrupted).

Mnemonic from the parent note: Zebras Carry New Vans.


L2 — Application

Goal: run the machine forward on given inputs, bit by bit, and read the flags off.

Recall Solution 2.1

leaves intact and — a pure add. Column carries (right to left): , , , , . Flags: (result nonzero), , , . Signed reading: , inside , so no overflow — consistent with . ✓

Recall Solution 2.2

Keep the low 4 bits: , and . Column carries: , , , , → so , . Flags: , , , . Interpretation: signed we wanted , which is below , so it overflowed → ✓. The is the unsigned carry and is irrelevant when we read these as signed numbers.

Recall Solution 2.3

Subtract means invert and set (Two's Complement): , . , . As signed, — correct, since . Flags: (negative ✓), , . Borrow: in a two's-complement subtractor, borrow . Here so — a borrow did occur, exactly right because .


L3 — Analysis

Goal: reason about WHY the machine behaves as it does, not just crank it.

Recall Solution 3.1

Carries: . So , . ; flags , , , . Why they disagree: unsigned fits in 4 bits (max ) → no carry out → . But signed exceeds , so the sign bit flipped () → . Same bits, two interpretations, two verdicts.

Recall Solution 3.2

Carry rule per bit: .

  • Bit 0: (generate).
  • Bit 1: , but and (propagate).
  • Bit 2: same pattern, (propagate).
  • Bit 3: , ... wait , so .

Correcting bit 3: , so . The carry propagates then dies. Result: . Weakness exposed: the carry had to travel through three stages one after another — the delay of a Ripple Carry Adder grows with bit-width, which is why we invent the Carry Lookahead Adder.

Recall Solution 3.3

With all , the inner OR is , so zero detected ✓. Why NOR: must be 1 only when every bit is 0. OR is 1 if any bit is 1; negating it gives 1 iff no bit is 1 — precisely the zero condition. A single OR-tree + inverter scales cleanly to any width.


L4 — Synthesis

Goal: assemble multiple pieces / design a small extension.

Recall Solution 4.1

is a logic op, so route it through the logic unit and add it as one more MUX input; the select lines choose it. The logic unit produces by inverting each bit in parallel (no carries involved). Verify on : . Flags: , ; and are meaningless for logic ops and ignored. Cost of the feature: one inverter bank + one MUX input — exactly the "add op = add circuit + one MUX line" principle from the parent note.

Recall Solution 4.2

Two bits are equal iff ; equality is (XNOR). For a 4-bit compare, use the subtract path: compute and read the flag. If then , so — the ALU already NORs all result bits, so equality comes for free from subtraction. This is exactly how a CPU's CMP instruction works (see Status Flags and Condition Codes).

Recall Solution 4.3

The signed less-than rule is (sign of , corrected for overflow). Compute : , : , so , . Carries: , . . Then is TRUE. Sanity: ✓.


L5 — Mastery

Goal: combine everything, handle a degenerate/limiting case, and self-check.

Recall Solution 5.1

, : . , . Carries: (the ripple), . Flags: (result is zero!), , , . Surprise 1: because — the inputs being negative is irrelevant; only watches the result bits. Surprise 2: means no borrow (), correct since . And confirms no signed overflow — a fully consistent, clean subtraction.

Recall Solution 5.2

, : . , . Carries: , . , so the machine claims . Deep reason: has no 4-bit two's-complement representation (range is ). Negating should give but can't fit, so overflow () fires — this is the famous " overflows" case. The flag is the hardware honestly telling you the answer left the representable range.

Recall Solution 5.3

, : . , . Carries: , . Flags: , , (no borrow), . Signed value of is ; check ✓ (in range, so as expected). Signed compare: , i.e. — TRUE ✓. Every flag is mutually consistent: correct value, no overflow, borrow-free per .


Active Recall (whole page)

Recall One-line self-quiz
  • Signed-less-than test? :::
  • Borrow flag in a two's-complement subtractor? ::: (borrow when )
  • Which flag caught overflowing signed 4-bit? ::: (while )
  • Why does negating overflow in 4 bits? ::: , no representation exists

Connections

  • Full Adder — the per-bit carry rule used throughout L2–L3
  • Two's Complement — negation, subtraction, and the edge case
  • Multiplexer — Problem 1.1's operation selector
  • Ripple Carry Adder — the carry-chain weakness in Problem 3.2
  • Carry Lookahead Adder — the fix for that weakness
  • Status Flags and Condition Codes — how drive branches and CMP
  • Datapath and Control Unit — where the ALU's state actually lives