C750 of 57
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C7 · Lesson 50 · Sandbox

Designing with gates and states

Two classic designs, worked from the specification to the logic. First, a 4-bit ripple-carry adder: four full adders in a chain, the circuit at the core of every processor's ALU. Second, a vending machine that sells a 15¢ item for nickels: a state machine that counts coins and dispenses on the third. Each design ends in Boolean equations, which you'll write and the cards will check against the truth table.

Play

  • A 4-bit adder: set A (A3 to A0) and B (B3 to B0) with the switches, and Cin. The outputs are the 4-bit sum and the carry out.
  • Add 1 to 15 (1111 + 0001). Watch the carry ripple up through all four stages, one gate delay at a time.
  • What does Cout mean when the inputs are unsigned numbers?

Predict

In a 4-bit ripple-carry adder with a gate delay of 1 tick per gate, roughly how long does adding 1111 + 0001 take to settle?

Name it

The two designs

4-bit ripple-carry adder. Four full adders. Stage k computes

Sk=Ak⊕Bk⊕CkCk+1=AkBk+Ck(Ak⊕Bk)

with C0=Cin and C4=Cout. For unsigned numbers, Cout=1 means the sum didn't fit in four bits. For signed numbers, overflow is instead when the carries into and out of the top stage differ.

Vending machine (15¢ item, nickels only, one coin per clock). States by cents so far: 0 (code 00), 5 (01), 10 (10). Input N = 1 when a nickel arrives this cycle; output V = 1 dispenses.

state S1S0N = 0 nextN = 1 nextV
00 (0¢)00010
01 (5¢)01100
10 (10¢)1000N

The dispense output depends on N as well as the state: a Mealy output. Writing each next-state bit as a function of N, S1 and S0, and simplifying, gives the logic you'll build below.

A nickel arrives three times (N is high across three clock edges). V pulses on the third.

Worked example

The 4-bit adder adds 9 and 8. What are its sum and carry out?

Show the solution
  1. Add. 9+8=17=100012
  2. Split the bits. The 4-bit sum is 0001 and the carry out is 1.

Answer the sum is 0001 and the carry out is 1.

Worked example

The vending machine receives 7 nickels, one per clock. How many items vend, and what state is it in?

Show the solution
  1. Count the items. It vends on every third nickel: 2 items.
  2. Find the state. The seventh nickel leaves it in the 5¢ state (01).

Answer 2 items, ending in the 5¢ state (01).

Check

Write a full adder's carry out, Cout, from inputs A, B and carry in C.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

From the vending machine's table, write the next value of S0.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

Write the next value of S1.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

Write the dispense output V.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

A 4-bit adder adds 0101 and 0001 with no carry in. What's the carry out?

Explain why

Why does a ripple-carry adder get slower as it gets wider?

Practice

Keep practicing

4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.