Skip to content
BIASED

What a computer system is

Layers from source to pixels, the stored-program idea and the fetch–decode–execute loop, the end of Dennard scaling, and the timing equation $I \times \mathrm{CPI} \times T_c$.

What happens when a program runs

A program is a text file. When we run it, characters appear on a screen a few milliseconds later, and between the two stand a compiler, a linker, an operating system, a processor executing billions of instructions per second, memory chips, a display driver and transistors switching on and off. Each of them is a layer built so that the layer above does not have to think about it. This course opens those layers one at a time, from the bits of a single number to a process talking to another over the network.

Notation. For the performance equation, II is the dynamic instruction count, CPI\mathrm{CPI} the average cycles per instruction, TcT_c the clock period and f=1/Tcf = 1/T_c the clock rate. Numbers written 0x… are hexadecimal; the next topic explains them.

Take the smallest C program that does something visible:

#include <stdio.h>
int main(void) { printf("hello, world\n"); return 0; }

Six steps stand between the source and the pixels:

  1. Source. hello.c is bytes on disk. The string "hello, world\n" alone is 13 bytes.
  2. Build. Preprocessor, compiler, assembler and linker turn C into an executable with the code of printf.
  3. Load. The shell asks the OS to create a process; the kernel maps the file and starts at the entry point.
  4. Execute. The processor fetches the instructions of main. printf ends in write(1, buffer, 13).
  5. System call. write switches into the kernel, which hands the 13 bytes to the terminal driver.
  6. Output. Glyphs become pixels on the display.

One function call involves every later section of the course: data representation, the instruction set, memory, the processor, system calls, processes, files and the toolchain.

Layers of abstraction

A computer is understandable because it is built in layers. Each layer offers an interface above and hides how it is implemented.

Layer Offers above Hides In this course
Language and runtime variables, functions registers, addresses Languages and compilers
OS processes, files, sockets devices, physical memory Operating system → networking
ISA instructions, registers, addresses the hardware that executes them RISC-V assembly
Microarchitecture an implementation of the ISA pipelines, caches Memory hierarchy → parallelism
Circuits gates, adders transistors where needed

The most important line is the instruction set architecture: the contract between hardware and software. Any program written for RISC-V runs on any RISC-V implementation, from a microcontroller to a server.

Abstraction does not make lower layers irrelevant. Layers leak. On an Apple M1, multiplying two 1024×10241024\times 1024 matrices with the textbook triple loop, clang -O0, took 5.4 s in one loop order and 1.5 s with two loops swapped — same result, same instruction count, different memory pattern. Nothing in C distinguishes the two; the difference lives in the caches, two layers down.

The stored-program computer

The first electronic computers were wired for one problem. ENIAC (1945) had about 18,000 vacuum tubes, drew 150 kW and did about 5,000 additions per second. Its program was the wiring: days of rewiring to change the problem.

Key idea. Store the program in the same memory as the data, as numbers. Fixed hardware runs any program by repeatedly fetching the next instruction and doing what it says. Programs become data that compilers and loaders can create.

Von Neumann’s First Draft (30 June 1945) describes a central arithmetic part, control, memory, and I/O, with instructions coded as numbers in memory. The Manchester Baby (21 June 1948) first ran a program from its own electronic memory: 17 instructions in 32 words of 32 bits. The organization is still called the von Neumann architecture: one memory for instructions and data, a processor with registers, ALU and control, a program counter (PC), and I/O. A Harvard machine has separate instruction and data memories; modern processors mix both ideas — one address space, but separate fast caches for instructions and data.

The fetch–decode–execute cycle

The control unit runs one loop forever:

  1. Fetch. Read the instruction at PC into the instruction register (IR).
  2. Decode. Split fields: operation, registers, constant.
  3. Execute. ALU computes a result, address or comparison.
  4. Write back. Write the result to a register (or memory).
  5. Next. PC ← PC + 4 for a 32-bit instruction, unless a jump or taken branch sets PC.

Worked example. Three RISC-V instructions loaded at 0x00400000 in RARS:

Address Word Assembly Effect
0x00400000 0x00500513 addi a0, zero, 5 a0 ← 5
0x00400004 0x00700593 addi a1, zero, 7 a1 ← 7
0x00400008 0x00B50633 add a2, a0, a1 a2 ← 12

On the third trip PC holds 0x00400008; fetch copies 0x00B50633; decode reads add, destination a2, sources a0 and a1; the ALU produces 12; PC becomes 0x0040000C. Memory holds only numbers — whether a word is an instruction depends on whether PC points at it.

Pipelines, superscalar and out-of-order designs overlap or reorder these stages, but must match one-at-a-time program-order semantics: that is what the ISA promises.

How processors got fast

Technology underneath the stored-program idea changed: vacuum tubes → transistors (from the late 1950s) → integrated circuits → Moore’s law (doubling of components about every two years after 1975). An Apple M1 (2020) has about 16 billion transistors — some seven million times the Intel 4004 (1971).

Dennard scaling (1974): shrink lengths and supply voltage by 1/κ1/\kappa. Capacitance falls as 1/κ1/\kappa, frequency rises as κ\kappa, and power per area stays constant. With κ≈2\kappa \approx \sqrt{2} each generation gave roughly twice the transistors and ~1.4× faster switches at the same power density. Single-processor performance grew about 52% per year from 1986 to 2003.

The end. Voltage cannot keep falling: leakage explodes below a few hundred millivolts. With VV fixed, power density grows as κ2\kappa^2. Chips dissipate only ~100 W before cooling fails. Around 2005 desktop clocks stalled near 3–4 GHz; single-thread growth fell to ~23%/year then ~3.5%/year after 2015.

Moore’s law kept supplying transistors, spent on more cores and accelerators (GPUs, TPUs). Neither speeds up an existing sequential program by itself — the program must be rewritten for parallelism.

The performance equation

Running time decomposes as

time=I×CPI×Tc=I×CPIf.\mathrm{time} = I \times \mathrm{CPI} \times T_c = \frac{I \times \mathrm{CPI}}{f}.

II is set by algorithm, language, compiler and ISA; CPI\mathrm{CPI} by microarchitecture, memory and the instruction mix; TcT_c by circuits and microarchitecture. With class fractions pjp_j and costs CPIj\mathrm{CPI}_j, CPI=∑jpj CPIj\mathrm{CPI} = \sum_j p_j\,\mathrm{CPI}_j.

Worked example. I=2×109I = 2\times 10^9, f=3f = 3 GHz, mix 50% arithmetic (CPI 1), 30% memory (CPI 2), 20% branches (CPI 1.5):

CPI=0.5⋅1+0.3⋅2+0.2⋅1.5=1.4,time=2×109⋅1.43×109=0.933 s.\mathrm{CPI} = 0.5\cdot 1 + 0.3\cdot 2 + 0.2\cdot 1.5 = 1.4, \qquad \mathrm{time} = \frac{2\times 10^9 \cdot 1.4}{3\times 10^9} = 0.933\,\mathrm{s}.

A better compiler removes 0.2×1090.2\times 10^9 arithmetic instructions. New cycle count 2.6×1092.6\times 10^9 → 0.867 s (7% faster), yet average CPI rises to 2.6/1.8=1.4442.6/1.8 = 1.444 because the cheap instructions left. No single factor measures performance — only the product.

The next topic, Bits, integers and byte order, unpacks what those memory numbers mean: unsigned and two’s-complement integers, overflow, and endianness.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.