ViewWiki

Lesson 4 of 4

A full adder and the processor.

Three bits in a column: the full adder, eight of them in a row in a processor's arithmetic unit, binary addition with carries, and what happens when the sum does not fit in a byte.

Step 1 of 5 · A full adder

Step 1 of 5

A full adder

A full adder adds three bits: aa⁠, bb⁠, and a carry in from the column to its right. Their sum is between 00⁠ and 33⁠, so it always fits in two bits: a sum digit and a carry out. It is built from two half adders: the first adds aa⁠ and bb⁠, the second adds the carry in to the result, and an OR gate joins the two carries.

This is a toy eight-bit processor. Its program adds the First number and the Second number, 28+1428 + 14⁠, and it is now decoding the add instruction. Predict, and then Zoom into the chip will raise a loupe over bit 3 of the arithmetic unit, one full adder, transistor by transistor.

To the question

Step 2 of 5

Column addition

Binary addition is the same column addition as at school, only with two digits: from right to left, column by column, and whenever a column reaches 2, write the sum digit and carry 1 to the left. Here is 28+1428 + 14⁠:

0001 1100+ 0000 1110\begin{array}{r} 0001\,1100 \\ +\ 0000\,1110 \\ \hline \end{array}⁠

Fill in the bottom row.

To the question

Step 3 of 5

Eight adders

The arithmetic unit, the ALU, is eight full adders in a row, one per bit. The carry out of each is the carry in of the one to its left. The loupe shows one of them: a CMOS full adder is 28 transistors, and a real processor holds millions of copies of circuits like it.

To the question

Step 4 of 5

Overflow

Eight adders hold eight bits, so a result over 255 does not fit. The carry out of the leftmost bit is not lost: the processor keeps it in the carry flag, which a program can test. The numbers here are 200200⁠ and 100100⁠. Move Clock tick to run the program, and see what is stored in cell 13.

To the question

Step 5 of 5

A byte in memory

The processor’s memory shows each cell as eight bits. The First number is stored in cell 14, and the second in cell 15. When you change the number, you write a new byte into memory.

To the question

Still of the How a CPU works 3D scene
Interactive scene

Loading the interactive version…

Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.

To the experiment

Practice · Predict, then look

The processor is about to add 28+1428 + 14⁠. The Zoom into the chip loupe will hold bit 3 of the arithmetic unit: a full adder receiving a=1a = 1⁠, b=1b = 1⁠ and a carry in of 1 from the bit to its right. What will it give?

To the experiment

Practice · Calculate

The first number is 0001 110020001\,1100_2⁠ and the second 0000 111020000\,1110_2⁠. Add them in base 2, column by column with carries, as the arithmetic unit does. What is the result in base ten?

To the experiment

Practice · Choose

This processor’s arithmetic unit adds two bytes. How is it built?

To the experiment

Practice · Calculate

The first number is 200200⁠ and the second 100100⁠. The result has to fit in one byte, in cell 13. Which number will be stored there?

To the experiment

Practice · Reach the target

Set the First number so that cell 14 holds the byte 0010 010120010\,0101_2⁠, and press Check.