seegongsik
Saved words
Structure

Who actually does the adding?

Last time we saw the "add" command. But who actually does that adding? And subtraction, and comparison? Let's meet the worker inside the CPU that handles only calculation, the ALU.

01

There's a part that only does calculation

Inside the CPU
there's a part
that handles only calculation.
Its name is the ALU.
Give it two numbers
and "which calculation to do,"
and it does that calculation
and produces a result.
It's like the heart of a calculator.

107
ALU
calculation worker
Result: 17

Two numbers go in the top, the result comes out the bottom.

ALU is short for
"arithmetic logic unit."
The name is grand,
but what it does is clear.
With the two numbers it gets,
do the calculation it's told.
Only that.

02

Pick the kind of calculation with a dial

The ALU is clever
because it doesn't do just one thing.
Addition,
subtraction,
and even comparison.
Turn the "which calculation" dial
and pick what you want,
and the same two numbers
give a different result.
Try turning it.

ALU · Add
10 7
17

Put in two numbers and pick a calculation.

You only changed the dial,
yet the same worker
did a different calculation, right?
This "which calculation"
is actually set by
last time's instruction.

03

The adder from lesson 6 lives here

Open up the ALU
and there's something familiar.
It's the adder we built in lesson 6.
Addition is handled by that adder.
Subtraction, comparison, and
logic operations like and, or,
it's a neighborhood
where small calculation circuits live together.

Inside the ALU
Adder
the one from lesson 6 (addition)
Subtractor
the taking-away calculation
Comparator
judges which is bigger
Logic circuits
the and, or, not from lesson 5
The adder from lesson 6 has come in as one part of the ALU and is working

The calculation circuits gathered inside the ALU.

The small circuits we built
one by one in lessons 5 and 6
were, in fact, the parts
that make up this ALU.
Small things gathered
into one calculation worker.

04

"Which is bigger" is answered by the ALU too

Among the ALU's jobs,
as important as calculation is comparison.
"Is this number bigger than that one?"
"Are the two numbers equal?"
To questions like these
it answers true or false.
This single true or false
later becomes the seed
of the fork called "if."

True

True is 1, false is 0. To a computer this too is, in the end, 0s and 1s.

"Is 10 bigger than 7?"
The answer is true.
This simple judgment
is enormously important.
A program looking at a situation
and choosing a path
all starts from this comparison.

05

The instruction turns the dial

Now two areas meet.
Remember last time's instruction?
The front part of "add,"
that operation code,
turns the ALU's dial itself.
"Add" sets it to addition,
"subtract" to subtraction.
The command tells the ALU
which calculation to do.

ALU · Add
10 7
17

An instruction's operation code → the ALU's dial.

The instruction decides what to do,
and the ALU does that calculation.
Now the CPU's two core parts
have come together.
Next time we'll look into
how these two work as one body,
the whole CPU.

In one lineThe ALU is the worker inside the CPU that handles calculation and comparison. The adder from lesson 6 lives in it too. An instruction's operation code sets which calculation the ALU does. The true or false of comparison is the seed of "if."
Was this helpful? Support seegongsik
Structure