How a Machine Learned to Choose: The Arithmetic Logic Unit

Planted 02026-08-01

Which answer should the machine keep?

How can one circuit add, subtract, compare, and transform numbers without being rebuilt each time?

How does a machine know which operation to perform when no gate understands what an operation is?

A logic gate follows one small rule. An adder joins many of those rules into arithmetic. But an adder has only one talent. Give it two numbers and it adds them because addition has been frozen into its wiring.

A general-purpose computer requires something stranger.

It must contain several possible actions at once—and allow signals inside the machine to decide which action becomes real.

Before that choice moved into circuitry, it belonged to human beings standing in front of the machine.

1. The women between the equation and the machine

In 1945, six women trained in mathematics were asked to program ENIAC, a vast electronic calculating machine being completed at the University of Pennsylvania.

Kathleen McNulty, Jean Jennings, Betty Snyder, Marlyn Wescoff, Frances Bilas, and Ruth Lichterman were not given a programming language. There was no manual explaining how to turn an equation into a sequence the machine could follow. They studied logical and electrical diagrams, interviewed engineers, designed procedures, created flowcharts, and eventually configured the machine using cables and thousands of switches.

The machine could perform thousands of additions in a second. But preparing it for a different problem could take days. The electronic calculation was fast; arranging what should happen was slow.

To program ENIAC, the women had to decide:

  • which unit should receive a value;
  • which operation should happen next;
  • where the result should travel;
  • when another unit should begin;
  • and what should happen when an intermediate result met some condition.

Then they had to embody those decisions in the machine’s physical configuration.

Programming was not yet a distant layer of text. It was an intimate negotiation with the machine’s body.

The device we now call an arithmetic logic unit, or ALU, was not invented in one dramatic moment beside ENIAC. But the programmers’ labor makes its purpose visible.

A useful machine must do more than calculate quickly.

It must be able to choose what kind of calculation this moment requires.

2. The machine with one talent

The previous step in our machine was an adder.

A half-adder combines two bits:

A   B   Sum   Carry
0   0    0      0
0   1    1      0
1   0    1      0
1   1    0      1

An XOR gate produces the sum. An AND gate produces the carry.

A full adder accepts a third input—the carry arriving from the previous column. Connect full adders together and the machine can add longer binary numbers.

This is already remarkable. No individual gate understands arithmetic, yet the network adds.

But the success hides a limitation.

The adder cannot decide not to add.

Its behavior is inseparable from its structure. The wires do not contain several possibilities and select one. They describe one transformation:

Two input numbers

      Adder

Their sum

Suppose we want the machine to perform a different operation.

Perhaps we want to know which bit positions are 1 in both numbers. That requires AND.

Perhaps we want the positions that are 1 in either number. That requires OR.

Perhaps we want to reverse every bit. That requires NOT.

Perhaps we want to subtract one number from another.

The obvious solution is to build a separate circuit for each job.

3. Too many correct answers

Imagine that the same two inputs enter several circuits at once:

                 ┌── Adder ─────── Sum

Input X ─────────┼── AND circuit ─ Bitwise AND

Input Y ─────────┼── OR circuit ── Bitwise OR

                 └── Other logic ─ Other result

Now the machine can produce several answers.

In fact, it produces them simultaneously.

The adder does not wait to learn whether addition was requested. The AND circuit does not ask whether its result will be useful. Once signals arrive and have time to propagate, every connected pathway responds according to its rule.

This creates a new problem:

Which result should continue through the machine?

A person could look at the outputs and choose one. That would make the human the machine’s selection mechanism.

But a computer that needs a person to choose after every operation is not yet directing its own sequence of work.

The choice must become another circuit.

4. The gate that does not calculate

A multiplexer selects between inputs.

It usually has two data inputs and one selection input:

A ───────┐
         ├── MUX ── Output
B ───────┘

           Select

Its rule is:

Select   Output
   0       A
   1       B

The multiplexer does not decide which input is better. It does not inspect the values for meaning. It simply obeys the selection signal.

This small circuit can be built from gates we already understand.

First, create the opposite of the selection bit:

NOT Select

Then allow A through only when Select is 0:

A AND (NOT Select)

Allow B through only when Select is 1:

B AND Select

Finally, combine the two pathways with OR:

Output = [A AND (NOT Select)] OR [B AND Select]

Only one pathway can be active at a time.

The multiplexer is therefore a gate made from gates—a small network whose entire purpose is controlled choice.

A one-bit multiplexer chooses between two bits. Place sixteen of them side by side and the same selection signal can choose between two sixteen-bit numbers.

Arrange multiplexers in a tree and one set of selection bits can choose among four, eight, or many possible inputs.

The circuit does not merely move information.

It allows one signal to determine which information matters next.

5. When a bit becomes a command

Consider two electrical signals traveling through the machine.

One belongs to a number:

0000000000000101

We interpret that pattern as five.

Another signal enters the selection input of a multiplexer:

1

We interpret that bit as “choose B.”

Physically, both are represented by the same kinds of high and low electrical conditions.

One is called data.

The other is called control.

Nothing inside the bit itself declares which role it plays. Its meaning comes from where the wire leads and what the surrounding circuit promises to do with it.

This is a hidden connection at the center of computing:

The machine’s values and the machine’s choices can be represented by the same physical alphabet.

A bit can contribute to a number.

A bit can say whether to invert another number.

A bit can select addition instead of AND.

A bit can permit a value to enter memory.

A bit can eventually determine whether the machine continues to the next instruction or jumps somewhere else.

The first logic gates transformed data.

Control signals transform the machine’s behavior.

An adder has one fixed future. Add multiplexers and control bits, and the same hardware can contain several possible futures.

The next challenge is deciding how much hardware must be duplicated—and how much can be reused.

Subtraction provides the surprising answer.

6. The subtractor we did not need

Suppose we already have a sixteen-bit adder and now want the machine to subtract.

The straightforward approach is to design a separate subtractor.

That can work. But it means more circuitry, more connections, and more physical space devoted to a task closely related to one the machine can already perform.

Could subtraction be disguised as addition?

In ordinary algebra:

X - Y = X + (-Y)

The problem becomes one of representation.

How should a fixed-width binary machine represent a negative number so that the existing adder produces the correct result?

A common solution is two’s complement.

To create the negative of a binary value:

  1. invert every bit;
  2. add one.

Using four bits, three is:

3 = 0011

Invert every bit:

1100

Add one:

1101

Within a four-bit two’s-complement system, 1101 represents negative three.

Now calculate five minus three:

  0101   5
+ 1101  -3
------
 10010

A four-bit circuit keeps only its four output bits. The carry beyond the available width falls away:

0010

That is two.

The same adder has performed subtraction.

The hardware needs only a controlled way to invert Y and a way to add the extra one. A signal can choose whether Y enters unchanged or inverted. Another controlled input can supply the starting carry.

The deeper breakthrough is not the trick itself.

It is the relationship between representation and machinery:

By choosing how numbers are encoded, people can make one physical circuit perform several conceptual operations.

The machine becomes more capable not because every ability receives a new dedicated mechanism, but because existing mechanisms are arranged to serve multiple meanings.

This is one of the reasons abstractions matter physically. A mathematical convention can remove hardware.

7. Building a circuit with several possible behaviors

We now possess the ingredients for a more general unit:

  • an adder;
  • bitwise logic such as AND;
  • inverters;
  • multiplexers;
  • and control bits.

They can be arranged in stages.

First, the inputs may be transformed:

Input X ──→ keep, zero, or invert ──→ Prepared X
Input Y ──→ keep, zero, or invert ──→ Prepared Y

Then several operations can be performed:

Prepared X ──┬──→ Add ──┐
             │           │
Prepared Y ──┴──→ AND ──┤──→ choose result

Other paths ─────────────┘

Finally, the chosen result may itself be transformed:

Chosen result ──→ keep or invert ──→ Output

This network is an arithmetic logic unit.

The name joins two families of operations:

  • arithmetic, such as addition, subtraction, incrementing, and negation;
  • logic, such as AND, OR, and bitwise inversion.

The ALU does not understand either family. It is a controlled arrangement of smaller promises.

A small number of physical choices produces a much larger family of useful behaviors.

This repeats the pattern from NAND itself:

Capability can live in composition rather than in the starting parts.

8. Why not build every operation directly?

A machine could contain a dedicated circuit for every operation anyone might request.

One pathway for addition.

Another for subtraction.

Another for multiplication.

Another for division.

Another for every comparison, shift, conversion, and mathematical function.

But hardware is not free.

Every pathway requires components. Components occupy area, consume energy, create heat, add delay, and introduce more connections that must be designed and tested.

A computer architect therefore faces a recurring tension:

More specialized hardware

More reuse of simpler hardware

Specialized circuitry can make an operation fast.

Reusable circuitry can make the machine smaller and simpler.

There is no single answer for every machine. A pocket calculator, a game console, a scientific workstation, and a tiny sensor may make different compromises.

The ALU is one such compromise made concrete.

It does not try to contain every imaginable calculation. It provides a compact set of transformations from which many useful operations can be built.

The machine’s power depends not only on what one ALU operation can do, but on what can happen when operations are placed in sequence.

Addition can be repeated.

A value can be shifted and added.

A comparison can influence what happens next.

A simple unit used many times can perform work far beyond any single pass through it.

But sequence introduces another requirement.

The machine must be able to notice something about the result it just produced.

9. The answer that answers back

An ALU usually produces a number or bit pattern.

It may also produce small signals describing that output.

Two especially useful questions are:

Is the result zero?
Is the result negative?

These are often called status outputs or flags.

A zero flag can be constructed by asking whether any output bit is 1.

If every bit is 0, the result is zero:

Output = 0000000000000000
Zero flag = 1

If even one bit is 1, it is not zero:

Output = 0000000000000100
Zero flag = 0

In a two’s-complement system, the highest-order bit can indicate whether the represented number is negative:

0xxxxxxxxxxxxxxx  → nonnegative
1xxxxxxxxxxxxxxx  → negative

The status signals do not explain the result.

They do not say whether zero is good or bad, expected or surprising, success or failure.

They report only another dependable fact.

Yet that fact creates the possibility of conditional behavior.

Suppose the machine is counting downward:

3
2
1
0

After each subtraction, the zero flag can answer:

Has the count reached zero?

If not, the machine may repeat.

If so, it may stop or begin a different task.

The ALU has not made the decision by itself. It has produced the evidence another part of the machine can use to decide.

This is the beginning of a loop.

It is also the beginning of a machine whose next action can depend on what happened before.

10. From choosing an answer to choosing a path

The multiplexer first appeared as a way to choose among numerical results.

But its deeper role is more general.

A machine constantly confronts alternatives:

Use this value or that value.
Store the new result or preserve the old one.
Read the next instruction or jump elsewhere.
Add the inputs or compare them.
Continue the loop or leave it.

Each alternative can be expressed as controlled routing.

The same logical pattern reappears at different scales:

Possible path A ──┐
                  ├── controlled choice ── actual path
Possible path B ──┘

A selection bit can choose an answer.

A status bit can help determine a selection bit.

The selected path produces a new result.

That result produces new status.

What began as a static network of fixed rules starts to form a chain of cause and consequence.

The machine is still not deciding in the human sense. It has no goal, doubt, preference, or understanding.

But it can now behave differently under different internal conditions.

Its future is no longer determined only by the wires placed during construction.

Its future also depends on the signals moving through those wires now.

11. The human hand moves upward

Return to the ENIAC programmers.

They translated a mathematical plan into switches, cables, timings, and routes. Their intelligence did not merely supply numbers to the machine. It arranged which operations would occur and how one result would cause another part of the machine to act.

The ALU moves part of that work inward.

Instead of a person physically selecting an arithmetic pathway, a control signal can select it.

Instead of rewiring separate circuits for addition and subtraction, the same adder can be reused under different control conditions.

Instead of a person inspecting a result to see whether it is zero, the machine can produce a zero flag electrically.

The human choice has not disappeared.

It has changed form.

Someone still has to determine the control signals:

Choose addition.
Keep X.
Invert Y.
Add one.
Preserve this result.
Use the next value.

A person could set those signals by hand, operation after operation.

But that would reproduce the original limitation at a smaller scale. The circuitry could switch in fractions of a second while waiting for a human being to tell it what to do next.

The remaining problem is therefore not how to give the machine more operations.

It is how to represent a plan for using those operations.

Could the choices themselves be written as bits?

Could those bits be stored?

Could the machine read them in sequence, use each pattern to control the ALU, preserve the result, and then find the next pattern without a person touching the wires?

12. What an arithmetic logic unit really is

An ALU is often drawn as a box:

        X ─────┐


          ┌─────────┐
Control ─→│   ALU   │─→ Output
          └─────────┘


        Y ─────┘

The box is useful, but it can conceal the achievement.

Inside are gates making small distinctions:

  • pass this signal;
  • block that signal;
  • invert these bits;
  • add these patterns;
  • choose this result;
  • report whether the output is zero.

No part knows that one control pattern means addition and another means subtraction.

No part knows that the output represents money, distance, a color, a character, or the position of an object in a game.

The ALU is not a tiny mathematician.

It is a place where behavior has become selectable.

That is the transformation.

The adder’s purpose was fixed in its construction.

The ALU’s construction contains several possible purposes, and control bits determine which one appears at its output.

The ENIAC programmers once stood between an equation and a wall of electronic machinery, turning a plan into physical pathways.

The next generation of machines would have to absorb more of that translation.

They would need to remember values.

They would need to remember control patterns.

They would need a way to move from one pattern to the next—and sometimes choose a different one because the ALU had produced zero or a negative result.

The next problem was no longer merely how a machine could calculate.

It was how a machine could follow a plan.