3.3.13 · D3Combinational Circuits

Worked examples — ALU design fundamentals

3,267 words15 min readBack to topic

The scenario matrix

Before working anything, let us list every case class a 4-bit ALU can produce. If we cover all rows, we have covered the topic.

# Cell (scenario class) What is special about it Example that hits it
1 Add, result fits (positive) ordinary case, no flags fire Ex 1
2 Add, signed overflow , sign corrupted Ex 2
3 Add, unsigned carry-out but signed still valid Ex 3
4 Subtract, positive result , = no borrow Ex 4
5 Subtract, negative result , = borrow, Ex 5
6 Zero / degenerate result , Zero flag Ex 6
7 Logic op (AND/OR/XOR) no carries; meaningless Ex 7
8 Real-world word problem temperature "wrap-around" Ex 8
9 Exam twist same bits, two interpretations Ex 9

Each example is tagged with the cell it fills.

Figure s01 below shows which bit each flag reads from — keep it in view; Example 2 refers back to the flag positions drawn here.


The worked examples


Active Recall

Recall One flag per scenario — can you match them?

Which single flag is the "headline" for each cell? Add fits (Ex1) ::: none fire — the plain, happy case Add signed overflow (Ex2) ::: (with ) — carries into/out of sign bit disagree Add unsigned carry (Ex3) ::: with — a 5th bit fell off but the signed sum still fit Subtract, (Ex4) ::: meaning no borrow Subtract, (Ex5) ::: (negative) and (borrow) (Ex6) ::: — the basis of the compare/equality test Logic AND/OR/XOR (Ex7) ::: only are meaningful; ignored


Connections

  • Full Adder — the per-column adder every example above steps through
  • Two's Complement — why negates, used in Ex 4, 5, 6, 9
  • Multiplexer — routes the logic result in Ex 7
  • Status Flags and Condition Codes — how drive branches
  • Ripple Carry Adder — the carry chain we traced bit by bit
  • Carry Lookahead Adder — a faster way to get the same carries
  • Datapath and Control Unit — where these operations get sequenced

Concept Map

produces

produces

produces

all bits zero

top bit

c4

c4

c4 xor c3

c4 xor c3

One bit pattern F

Addition path

Subtraction path flip B plus one

Logic path AND OR XOR

Zero flag Z

Carry flag C unsigned

Negative flag N sign bit

Overflow flag V signed