Hardware Foundations: CPU and Memory
Central Processing Unit
The CPU (Central Processing Unit) is the computation and control core of a computer system and executes program instructions.
Its core components include:
- Control unit (CU): fetches and decodes instructions and coordinates processor operations.
- Arithmetic-logic unit (ALU): circuits that perform arithmetic and logical operations.
- Registers: small, high-speed storage components that temporarily hold instructions, data, and addresses.
Fetch, Decode, Execute
Instruction processing in most modern processors can be described as a fetch-decode-execute cycle. The von Neumann architecture is a stored-program architecture with a shared instruction/data memory system, not another name for the instruction cycle.
Step through a CPU datapath
PC = 0; registers and memory[20] are zero.
KNOWLEDGE QUIZ
CPU Information
Python's multiprocessing module can report the system's logical CPU count.
import multiprocessing
print(f"System logical CPUs: {multiprocessing.cpu_count()}")Python's psutil module also provides system hardware information.
import psutil
physical = psutil.cpu_count(logical=False)
logical = psutil.cpu_count(logical=True)
times = psutil.cpu_times()
print(f"Physical cores: {physical if physical is not None else 'unknown'}")
print(f"Logical CPUs: {logical if logical is not None else 'unknown'}")
print(f"CPU time (user): {times.user:.2f} seconds")
print(f"CPU time (system): {times.system:.2f} seconds")
print(f"CPU time (idle): {times.idle:.2f} seconds")Storage Units
Storage units include bit (b), B, kB, MB, GB, TB, PB, EB, ZB, and YB.
A bit is the smallest storage unit and holds one binary digit.
A byte contains eight bits. An English letter in ASCII takes one byte; a Chinese character's byte count depends on encoding, with common Chinese characters taking three bytes in UTF-8. A word is an architecture-dependent data unit, not a synonym for a Chinese character.
| Quantity | Equals |
|---|---|
| 8 bits | 1 byte |
| 1024 bytes | 1 KiB |
| 1024 KiB | 1 MiB |
| 1024 MiB | 1 GiB |
| 1024 GiB | 1 TiB |
| 1024 TiB | 1 PiB |
| 1024 PiB | 1 EiB |
| 1024 EiB | 1 ZiB |
| 1024 ZiB | 1 YiB |
Disk manufacturers commonly use decimal units, with 1000 bytes per kB. These are standard units, not fraudulent accounting.
Storage Devices and the Memory Hierarchy
Storage devices preserve digital information using electrical, magnetic, or optical media. The hierarchy includes registers, CPU cache, main memory, SSDs, hard disks, optical disks, and magnetic tape. Higher levels are generally faster, smaller, and more expensive per bit.
Storage hierarchy
Inside the CPU. Fastest in this hierarchy, smallest capacity, high cost per bit.
KNOWLEDGE QUIZ
Recognize storage devices
Compare devices in the storage hierarchy.
- Name three storage devices.
- Which is generally faster: registers or main memory, SSDs or mechanical hard disks?
- How do capacity and speed generally change toward the bottom of the hierarchy?