From MOSFETs to the CPU

How can these simple components be connected to store data, perform calculations, and execute a program?

A MOSFET, or metal-oxide-semiconductor field-effect transistor, is a fundamental building block of modern digital electronics. It acts like an electrically controlled switch: a voltage applied to its gate controls whether current can flow between its source and drain terminals.

Modern logic circuits are built using CMOS technology, which combines NMOS and PMOS transistors to implement four basic logic operations: the AND gate (symbol: Y=A∧BY=A\land B), the OR gate (symbol: Y=A∨BY=A\lor B), the NOT gate (symbol: Y=¬AY=\lnot A, implemented by an inverter in CMOS), and the XOR gate (symbol: Y=A⊕BY=A\oplus B). An XOR gate outputs 1 when its inputs are different. It is particularly useful in arithmetic circuits because it can produce the sum bit when adding two binary digits, before accounting for a carry from another position.

How a Circuit Remembers: From a Latch to a Register

By connecting logic gates so that their outputs feed back into the circuit, we can create a circuit that maintains one of two stable states. One state represents 0; the other represents 1. This is the principle behind a bistable circuit.

In its basic form, an SR latch has set and reset inputs. We can make it more practical by adding an Enable signal, creating a gated latch that accepts new data when enabled and retains its previous state when disabled.

One bit is useful, but a computer needs to hold many bits together. By combining storage circuits, we can build a register. An 8-bit register, for example, can hold 01000001. A CPU uses registers to temporarily hold numbers, addresses, instruction information, and intermediate calculation results.

There is an important distinction between a latch and a flip-flop. A latch is level-sensitive: while its Enable signal is active, its output can follow the input. A typical flip-flop is edge-triggered: it captures its input at a particular transition of the clock signal, such as the rising edge. A clock is a repeating electrical signal that helps synchronize operations across a digital circuit. Registers built from flip-flops are common in CPUs, including those that hold the program counter and other architectural state.

How Can Millions or Billions of Memory Cells Share So Few Wires?

The key idea is to organize memory as an array of rows and columns. The cells share wires, and the memory controller selects the cells it needs at any given moment.

Consider a small array containing 16 cells, arranged in four rows and four columns. Each row has a word line, and each column has a bit line. The address decoder determines which row to select. For example, a two-bit row address can select one of four rows. If the address is 10, the decoder activates the third row, assuming rows are numbered from zero.

The selected row’s word line activates the access transistors of its cells. The bit lines then carry data between the selected cells and the surrounding read/write circuitry. The word line selects the cells; the bit line carries the data.

Real memory systems have more complex arrangements than this small example. They may use banks, multiple address and data wires, sense amplifiers, precharge circuits, and separate control signals. But the core principle remains the same: select a portion of the array, then use shared wires to read or write its data.

How the CPU Executes a Program

A CPU contains registers, arithmetic circuits, control logic, and connections to memory and other components. Its job is to execute machine instructions according to the architecture it implements.

This is where the program counter comes in. On x86-64 processors, the instruction pointer is called RIP. Other architectures use names such as PC, or Program Counter. It holds the address of the next instruction to be fetched.

If an instruction occupies three bytes, the next instruction’s address is three bytes higher during normal sequential execution. However, a jump or branch can direct the processor to another address. This is how a program implements loops, decisions, function calls, and other control flow.

The basic cycle can be described as fetch, decode, and execute: the CPU fetches instruction bytes from memory, decodes them to determine the required operation, and executes that operation. The program, ultimately, is a sequence of machine instructions that the CPU’s hardware fetches and carries out.

Leave a Reply