The Processor
We now have all the essential ingredients to hand: logic gates that compute, registers that remember and a clock that synchronises their beats. Putting them together, we give birth to an astonishing machine: a processor that is not locked into a single fixed purpose but obediently carries out, step by step, any list of instructions coded as numbers.
Terms: datapath selector arithmetic and logic unit instruction operation code program counter fetch · decode · execute frequency
The datapath
Up to this point we have forged isolated parts: logic gates, an adder capable of additions and subtractions, and registers that hold bytes. Now the moment has come to connect them into a living mechanism. Between two successive beats of the clock, an unbroken choreography unfolds inside the chip: values leave the source registers, travel along copper buses, cross the computing gates of the adder and arrive, transformed, at the gates of the destination registers. There they settle quietly and wait. At the next clock edge the new result is drawn inside, and the cycle begins again. This inner motorway along which the electric signals travel is called the datapath.
From this follows an iron rule of physics that ties space to time: the processor’s clock cannot beat faster than the time a signal needs to cross the most laborious and longest route in the circuit. If the binary carry needs a fraction of a nanosecond to propagate through all eight columns of the adder, the clock must leave enough time for the waters to settle. Were we to hurry the rhythm beyond measure, the registers would capture incomplete results — a jumble of bits not yet finished.
The arithmetic unit
The adder we studied does not live in isolation. Beside it sit the circuits of the other basic operations: the subtraction module and the logic gates that work bit by bit (AND, OR, inversion). At their common output stands a kind of railway point called a selector (or multiplexer): a circuit that receives the results of all the operations at once but lets only the one asked for by the command signal pass on. The whole assembly is called the arithmetic and logic unit (ALU).
Notice a fascinating strategy of the digital world: when two numbers arrive, the ALU computes all the possible operations at once — the addition, the subtraction, the logical conjunction — and the selector simply picks the wanted result and throws the others in the bin. This appearance of waste is quite deliberate: in electronics, transistors are cheap and minute, but time is extremely precious. Waiting to start only the necessary circuit would take longer than letting them all compute in parallel. In hardware it is often far quicker to compute everything and choose afterwards.
The instruction is a number
How does the machine know what to do at each step? The order must be expressed in the only language the circuits understand: strings of bits. An instruction is not an abstract spell but a plain binary number divided into preset boxes. Each group of bits acts like a mechanical key: a few bits steer the selector’s points towards the wanted operation, and the others pick the registers that send or receive the data.
In our small demonstration computer below, every instruction is one byte long (8 bits), divided into three logical fields. The first three bits are the operation code (the opcode): with three bits we can choose one of eight possible commands (load a value, add, subtract, jump and so on). The next two bits name the destination register. The last three bits make up the operand: a direct numeric value, a memory address or the code of a second register.
When an operation works with two registers, only the last two of the three operand bits are needed (since we have only four registers to tell apart). The bit left over is simply ignored by the decoder. Such small compromises and unused spaces are found in every real processor in history.
The execution cycle
To move through a program without getting lost, the machine needs a page marker: a special register called the program counter (PC). It permanently holds the memory address of the instruction that is to be carried out next.
Once started, the processor tirelessly repeats a loop in three movements, called the instruction cycle. The first step is the fetch (Fetch): the program counter points at a memory box, and the byte lying there is read and brought into the processor. The second step is the decode (Decode): the byte is taken apart into its fields, and the operation code sends electrical pulses to the selectors of the datapath, preparing the right circuits. The third step is the execute (Execute): the values pass through the arithmetic unit, the result is saved in the target register, and the program counter advances by 1 towards the next instruction (or jumps to an entirely different address, if the instruction asked for that).
This mechanism of the conditional jump is the magic spark of computers. Without it a processor would be a rigid music box, running through a fixed list of commands from beginning to end once and once only. Thanks to the conditional jump (“if the last result is not zero, jump back to step 2”), the machine can take decisions, repeat loops of computation and react flexibly to the data it handles. From the marriage of arithmetic and the jump is born what we rightly call autonomous behaviour.
The machine at work
Look at the panel below: here is the whole computer assembled and ready to go — the memory with the program, the address counter, the decoder, the internal registers and the datapath. The program loaded has a clear task: add the numbers from 1 to 5. Each press of “One beat” goes through one phase of the cycle (fetch, decode or execute), so a complete instruction is fulfilled every three beats.
the program
the registers
what it showed
Try the second program in the menu as well: it multiplies the numbers 3 and 4. Our machine has no special multiplication gate; instead the program adds the number 3 four times over, subtracting 1 from a counter register until it reaches zero. Here is the central lesson of computing: any complex operation missing from the hardware can be built by cleverly composing a few elementary instructions.
Frequency
The speed at which the processor’s heart beats is called the clock frequency and is measured in hertz. A frequency of three gigahertz (3 GHz) means the clock ticks three billion times a second. At that dizzying scale one beat lasts only a third of a nanosecond — the tiny span in which light barely manages to travel ten centimetres through space.
As we have seen, an instruction needs several beats to complete. How, then, do today’s computers manage to be so fast? Through a technique called the assembly line (pipelining), rather like an automatic laundry: while one garment is drying in the dryer (the execute phase), the next is being washed in the machine (decoding), and a third is being sorted in the basket (fetching). Each garment takes three hours in all, but every hour a clean garment comes out. By working on several commands in different phases, modern processors finish on average nearly one instruction at every beat of the clock.
Let us take one last step back and look carefully: the program our machine carried out was written in memory as ordinary bytes, exactly like the numbers it added. Nothing in the physical structure of the memory tells an instruction apart from any other piece of numeric data. What turns an inert number into a living command is only the fact that the program counter pointed at it. This epoch-making realisation — the merging of program and data in the same memory — opens up an entirely new world, which we shall explore in the next lesson.