Lite / Building Machines That Respond / Week 17
Multi-bit addition and the ripple-carry adder
Adding 0111 + 0001 changes every single bit of the answer. How long does a circuit have to wait before it can trust the result?
Why should I care?
Adders set the speed of a processor's arithmetic. Understanding why the carry has to ripple, and what that costs in time, is the first step towards the faster adder designs used in every modern chip.
- Add multi-bit binary numbers by hand, showing every carry.
- Trace a ripple-carry adder column by column and identify carry out.
- Estimate how the worst-case delay of a ripple-carry adder grows with the number of bits.
Predict
Add 0110 + 0111 in 4-bit binary. What is the result?
- 1101
- 1011
- 0111
- 1111
Guess first, then reveal
6 + 7 = 13 = 1101. Column by column from the right: 0 + 1 = 1; 1 + 1 = 10 (write 0, carry 1); 1 + 1 + 1 = 11 (write 1, carry 1); 0 + 0 + 1 = 1.
Discover
Do Level 3 of the virtual computer: fill in the full adder table, find two 4-bit numbers whose carry ripples through all four columns (watch the settle clock), and work out how many gate delays the 4-bit adder needs before its carry out is certain.
What the interactive shows (text version)
The virtual computer's ripple-carry adder shows four full adders in a row with carries passing right to left and a settle clock counting gate delays. Adding 0111 and 1001 makes the carry ripple through all four columns, and the carry out is certain after 9 gate delays.
Watch (optional)
Watch for: Notice how each chip's carry output is wired to the next chip's carry input, and that the last carry is where overflow shows up.
Shows step by step how a handful of gates add binary numbers, using real chips you can buy.
“Learn how computers add numbers and build a 4 bit adder circuit” by Ben Eater (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
By hand: right to left
Line the numbers up, start at the rightmost column and add the two bits plus any carry. Write the sum bit and carry the rest. 1011 + 0110: 1 + 0 = 1; 1 + 1 = 10 → 0 carry 1; 0 + 1 + 1 = 10 → 0 carry 1; 1 + 0 + 1 = 10 → 0 carry 1. Result 1 0001 = 17 = 11 + 6.
The ripple-carry adder
One full adder per column, each carry out wired to the next carry in. It is simple and small, but a column cannot be sure of its answer until the carry from the right has arrived, so the carry ripples across the whole adder.
Worst-case delay
Each gate takes a little time to settle. In the virtual computer's model the first column's carry is ready after 3 gate delays (XOR, AND, OR), and each further column adds 2. A 4-bit adder needs 3 + 2 × 3 = 9 delays; 32 bits would need 65. Faster designs, such as carry-lookahead, compute carries in parallel at the cost of more gates.
Explain it another way
Intuitive
A row of dominoes: the last one cannot fall until every one before it has. The more bits, the longer the row.
Technical
Ripple-carry delay is O(n) in the number of bits because the carry chain is serial. Carry-lookahead adders compute generate (A·B) and propagate (A ⊕ B) signals per bit and combine them in a tree, giving roughly O(log n) delay.
Mathematical
With delay 3 for the first carry and 2 per further bit, the n-bit ripple delay is 3 + 2(n − 1) = 2n + 1 gate delays: 9 for 4 bits, 17 for 8 bits, 65 for 32 bits.
Applied
Processor designers choose adder structures to meet a clock speed: the adder must settle within one clock tick. Small microcontrollers can afford ripple-like adders; fast desktop chips cannot.
Worked example 1
Add 0101 + 0011 by hand, showing carries.
1 + 1 = 10 → 0 carry 1. 0 + 1 + 1 = 10 → 0 carry 1. 1 + 0 + 1 = 10 → 0 carry 1. 0 + 0 + 1 = 1. Result 1000 = 8 = 5 + 3.
Common mix-ups
All the bits of a sum appear at the same instant.
✓ In a ripple-carry adder the higher bits wait for carries from the lower ones.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Finish BUILD 008 Level 3. Then, using the delay model above, make a table of worst-case delay for 4, 8, 16 and 32 bits and describe the pattern in one sentence.
Reflect
If you were designing a very fast processor, which would you rather spend: more gates or more time? Why?
Write your answer on paper or in your own notes. Lite never stores what you write.