# Part IV: Time, execution and controlThe clock imposes order; the CPU fetches, decodes, and executes instructions; parallelism and specialized units extend that model.

## Time

### Time is the missing ingredient

Computation requires not only correct rules, but the correct sequencing of those rules over time. At the physical level, electronic components do not naturally update in a synchronized way: Signals propagate through wires at finite speeds, and transistors respond with small delays that vary with temperature, voltage, and manufacturing imperfections. If every component reacted immediately and independently, large systems would become unstable as signals raced, overlapped, and contradicted one another.

Eliminating these delays is impossible, that's why computers rely on a shared temporal reference: the clock.

### The clock

The clock is a physical device that produces a regular, repeating signal: high - low - high - low, and so on. This signal divides time into a sequence of discrete steps, creating a shared rhythm that all components follow. Each repetition is called a clock cycle. Each cycle defines the moments at which the system is allowed to change state, with the components agreeing to observe inputs at specific instants and update outputs only at those instants.

Between these moments, signals may fluctuate internally, but their effects are ignored.

Physically, a clock is an oscillator: a circuit that produces a regular, repeating electrical signal. In many systems this is achieved with a quartz crystal, which uses the piezoelectric effect (applying a voltage makes the crystal vibrate, and that vibration produces a stable electrical oscillation at a precise natural frequency). Other systems generate clocks using purely electronic circuits built from transistors, which are easier to integrate but can be less stable.

Often, a quartz crystal provides a reference, and then additional circuits derive faster or slower clock signals from it.

The speed of a clock is described by how many cycles it produces per second. One cycle per second is called a hertz. A clock running at one million cycles per second runs at one megahertz (MHz); one billion cycles per second is one gigahertz (GHz). Today, quartz crystals in computers typically oscillate at relatively low frequencies (millions of cycles per second) because they are most stable there.

Inside the computer, electronic circuits take this "slow", accurate rhythm and multiply it, generating much faster clocks that tick billions of times per second.

However, this ticking pulse is not perfectly precise. It can wobble slightly, and also it reaches different parts of the machine at slightly different times. That's why systems need to be designed with enough margin. There is always a trade-off: if the clock ticks very fast, the computer can take more steps per second, but leaves less time for signals to settle, increasing the risk of errors. If it ticks more slowly, the machine is calmer and more reliable, but slower overall.

The clock's real job is not to measure time accurately, its job is to create order. It tells the machine when one step ends and the next begins, turning a messy physical process into something that behaves like a clean, step-by-step procedure.

## The CPU

Once time is imposed through a clock, logic and memory can finally be used in a controlled way. However, nothing in clocks, gates, or memory determines which operation is performed next, or how one operation leads to another. What is required is a component that executes operations and controls their order over time. That component is the CPU.

### An execution engine

A CPU (Central Processing Unit) is an arrangement of logic circuits, registers, and control wiring, all synchronized by the clock. The CPU's defining property is that it executes, which means that the system moves from one state to the next in an orderly sequence. Each step consumes some information, transforms it, and produces a new state that becomes the starting point for the next step.

The CPU's work can be summarized as a repeating pattern, which happens billions of times per second:

1. Obtain a description of what to do next
2. Activate the circuits that perform that action
3. Update internal state to reflect the result
4. Advance to the next step

### The instruction cycle

The "descriptions of what to do next" are called instructions. An instruction is a fixed pattern of bits stored in memory. An instruction, however, cannot describe any arbitrary action. Each CPU is built with a limited set of basic operations that it can perform. These operations are simple, but they are sufficient to construct any larger computation.

- Some instructions move data. They copy values between registers, or between memory and registers, or load small constant values directly into the CPU.
- Other instructions perform arithmetic or logic. They add or subtract numbers, compare values, or combine bits using logical operations. These instructions operate on data already present inside the CPU, typically stored in registers.
- Other instructions control execution itself. They can change which instruction will be executed next, allowing the machine to repeat steps, skip sections, or branch based on previous results.

Inside the CPU, instruction bits are connected to circuitry in such a way that different bit patterns activate different signal paths. One pattern may enable an adder, another may cause a value to be copied, another may change which instruction will be executed next. In a way, the CPU does not understand instructions, each instruction is simply a trigger for a particular physical behavior that has been wired into the machine in advance.

Execution follows a structured loop called the instruction cycle, which is synchronized by the clock, and can be modeled as three conceptual steps:

#### Fetch

"What should I do next?"

In this step, the CPU retrieves the next instruction from memory. The choice of which instruction is retrieved is determined by a value stored inside the CPU (program counter or instruction pointer), which changes from one cycle to the next.

#### Decode

"What does this mean?"

The fetched instruction is just a pattern of bits, and now the CPU must interpret it. During decode, the CPU determines which operation is requested (add, load, jump, compare, etc.), and it figures out which data is involved.

To determine this, the instruction's bits are fed into fixed decoding circuits, that turn control signals on or off. This selects which internal wires carry signals, which components are enabled, and which paths are blocked. Decoding is about configuring the machine, a setup step. The instruction's bits temporarily reshape how the CPU is internally wired, preparing the machine for execution.

#### Execute

"Do it"

In this step, the configuration that was set up during decode is actually used. Signals flow through the enabled circuits, and the operation physically takes place inside the CPU. For arithmetic or logic instructions, values from registers pass through Arithmetic Logic Units (ALUs), and the result is written back to a register. For data-movement instructions, execution opens paths that copy values between registers or between memory (SRAM) and the CPU.

For control instructions, execution changes the value that determines which instruction will be fetched next.

The results of this work are stored in registers, execution ends, and the CPU immediately starts the next instruction cycle.

## Beyond the CPU

### Communication

The CPU does not operate in isolation. Instructions must come from somewhere, results must go somewhere, and the entire system must coordinate across multiple components. All communication between the CPU and the rest of the machine happens through shared communication structures called buses. Over these buses, the CPU sends three kinds of information: addresses (where to act), data (what to transfer), and control signals (what kind of action to perform, such as read or write).

By placing patterns of bits on these shared wires, the CPU can read from memory (RAM), write results, or interact with hardware devices. The CPU does not need to know how those components work internally, only how to communicate with them.

### Parallelism and overlap

The instruction cycle describes a clean, sequential process. However, real computers do not operate one step at a time. If the CPU were forced to do exactly one thing at a time and wait for each step to fully complete before starting anything else, most of the hardware would spend a lot of time just waiting.

To avoid this, computers are built to overlap work in time. Inside a single CPU, different parts work in parallel. While one instruction is being executed, others may already be fetched or decoded. Modern CPUs also contain multiple independent execution units (cores) within the same chip, allowing the machine to perform parallel work: multiple computations being executed at the same time, sharing memory and devices but not waiting on each other unless necessary.

Why not just increase the clock speed indefinitely? Because of physical limits: increasing clock speed causes more frequent switching, higher power consumption, and excessive heat, and beyond a certain point signals are no longer reliable, making faster clocks impractical. As more things happen at once, execution becomes less about speed and more about coordination.

### Specialized processing units

A processing unit is any hardware component whose job is to execute computations. There are multiple kinds of processing units, each optimized for a different kind of work:

- **CPU: Central Processing Unit.** General-purpose processor designed to execute many different kinds of instructions. They are extremely flexible, but not very efficient, specially when performing simple operations repeatedly over large amounts of data. They are found in almost every computing device. CPUs can follow different architectures, which define how instructions are represented and executed.

  The most common architectures today are x86 (used by companies such as Intel and AMD) and ARM (used by companies such as Apple, Qualcomm, Samsung, and MediaTek).

- **GPU: Graphics Processing Unit.** Processor optimized for executing the same operation on many data elements in parallel. It consists of thousands of simple arithmetic units that operate simultaneously, making it extremely efficient for data-parallel workloads. This design sacrifices flexibility. GPUs are used for graphics rendering, image and video processing, scientific simulations, and many machine-learning workloads, and are found in personal computers, game consoles, smartphones, and data centers.

- **TPU / NPU: Tensor or Neural Processing Unit.** Specialized processor with hardware specifically designed to execute neural-network operations, such as matrix multiplication and convolution, with maximal energy efficiency. They are commonly used for AI workloads, and are found in smartphones, AI devices, and data centers.

- **ASIC: Application-Specific Integrated Circuit.** Specialized processor with hardware designed to perform a single task or a very narrow class of tasks as efficiently as possible. Its computation is fixed directly into the circuitry, eliminating any unnecessary flexibility and providing extreme performance and energy efficiency. Has minimal flexibility, once manufactured, its function cannot be changed. ASICs are used for tasks such as cryptographic hashing (e.g. cryptocurrency mining) or video encoding/decoding, and are found in specialized hardware.

- **Other specialized processors:** This includes processors such as DSP, FPGA, MCU, etc. These are designed to prioritize efficiency, predictability, or low power usage over flexibility. They are commonly used in embedded systems, industrial equipment, vehicles, sensors, and consumer electronics.

### The layers above and below

So far, we have described a machine that can execute instructions. Each instruction is a fixed pattern of bits that triggers a specific, pre-wired physical behavior. This set of instructions is known as machine code, the lowest-level language the hardware can execute.

What is still missing is how humans describe what these instructions should contain, how these instructions reach the CPU, and how multiple tasks are organized sharing the same machine. The next part climbs another abstraction layer: from instructions to software.
