Published by Patrick Mutisya · 14 days ago
The CPU is the brain of a computer system. It executes instructions, performs arithmetic and logic operations, and controls the flow of data between the processor, memory and peripheral devices. In this section we focus on how the CPU connects to peripherals through various types of ports.
The CPU communicates with other components via buses. A bus is a collection of wires that carry data, addresses and control signals.
Peripheral devices are connected to the CPU through ports. There are two main methods of port addressing:
In MMIO, the CPU treats peripheral registers as if they were memory locations. In PMIO, the CPU uses specific instructions (e.g., IN/OUT on x86) to read from or write to port addresses.
| Port Type | Typical Use | Data Transfer Mode | Speed (approx.) |
|---|---|---|---|
| Serial Port (UART) | Keyboard, Modem, Serial console | Byte‑by‑byte, asynchronous | 115.2 kbit/s |
| Parallel Port (LPT) | Printers, legacy devices | 8‑bit parallel, synchronous | 1–2 Mbit/s |
| USB (Universal Serial Bus) | Keyboards, mice, storage, networking | Packet‑based, full/low/high speed | 12 Mbit/s (USB 1.1), 480 Mbit/s (USB 2.0) |
| PCIe (Peripheral Component Interconnect Express) | Graphics cards, SSDs, network cards | High‑bandwidth, point‑to‑point | 2.5 Gbit/s per lane (PCIe 1.0), up to 32 Gbit/s (PCIe 4.0) |
| SPI (Serial Peripheral Interface) | Microcontrollers, sensors | Full‑duplex, synchronous | Up to 10 Mbit/s |
| I²C (Inter‑Integrated Circuit) | Sensor interfaces, EEPROMs | Half‑duplex, synchronous | Up to 400 kbit/s (Fast mode) |
Suppose a peripheral device has a base address of \$0x4000\$ and exposes four 8‑bit registers at offsets \$0x00\$, \$0x01\$, \$0x02\$, and \$0x03\$. The CPU can read the second register with the following address calculation:
\$\$
\text{Address} = \text{Base} + \text{Offset} = 0x4000 + 0x01 = 0x4001
\$\$
The CPU then performs a read operation on the data bus at address \$0x4001\$ to obtain the register value.
Peripherals often signal the CPU via interrupt lines. When an interrupt occurs, the CPU temporarily stops its current task, saves its state, and jumps to an interrupt service routine (ISR). The ISR typically reads or writes data through the appropriate port to acknowledge or process the event.