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, is the dynamic instruction count, the average cycles per instruction, the clock period and 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:
- Source.
hello.cis bytes on disk. The string"hello, world\n"alone is 13 bytes. - Build. Preprocessor, compiler, assembler and linker turn C into an executable with the code of
printf. - Load. The shell asks the OS to create a process; the kernel maps the file and starts at the entry point.
- Execute. The processor fetches the instructions of
main.printfends inwrite(1, buffer, 13). - System call.
writeswitches into the kernel, which hands the 13 bytes to the terminal driver. - 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.