Find a course

Module 5: Software, Startup and ConnectionsLesson 10 of 1114 min

From Code to a Running Program

Compare compilers and interpreters, follow a computer from power button to desktop, and see how the operating system loads and runs your apps.

Step 1 of 12Learn

One line of Python, thousands of instructions

Type print(2 + 3) into Python and press Enter. The number 5 appears. The CPU, however, has no idea what print means. It only understands machine code for its own instruction set.

Between your line of code and the CPU sits a chain of translators. A high-level language such as Python, JavaScript, Java or C lets people write in something close to human logic: variables, loops, functions, text. Programs called compilers and interpreters turn that into the small steps a processor can run.

This is the abstraction ladder from the first lesson in action. The programmer thinks about show the total. The language runtime turns that into operations on strings and numbers. The operating system turns write to the screen into commands for the graphics hardware. And the CPU executes it all as loads, stores, adds and jumps, perhaps tens of thousands of them for that one short line.

Understanding this chain helps explain everyday things: why some programs start instantly and others need a moment, why an app must be built separately for phones and PCs, and why a bug in one layer can surface far away in another.

Step 2 of 12Diagram

From your code to the CPU

From your code to the CPUProcess diagram: Source code → Compiler or interpreter → Machine code → CPU runs it.Source codeCompiler orinterpreterMachine codeCPU runs it

Tap a shape with to see more.

Source code

print(2 + 3), written for people.

Compiler or interpreter

Translates into instructions the machine can run.

Machine code

Binary instructions for one instruction set.

CPU runs it

Step 3 of 12Compare

Compiled vs. interpreted

AspectCompilerInterpreter
When translation happensAll at once, before the program runsWhile the program runs, statement by statement
OutputA standalone executable file of machine codeNo separate file; the interpreter runs the source directly
Speed when runningUsually very fastUsually slower, since translation work happens during the run
ErrorsMany errors reported before the program ever runsErrors appear when the faulty line is reached
Typical languagesC, C++, Rust, GoPython, JavaScript (often with a JIT compiler), Ruby

Step 4 of 12Learn

Shades of gray: bytecode and JIT

Real languages blur the line between compiling and interpreting.

Java and C# compile source code into bytecode, a compact instruction set for an imaginary machine. A virtual machine then runs that bytecode on whatever real processor you have. That's how the same Java program runs on Windows, Mac and Linux without being rebuilt.

Python also compiles your code to bytecode behind the scenes (the .pyc files you may have seen), then interprets that bytecode.

Modern JavaScript engines in browsers use just-in-time (JIT) compilation. They start by interpreting your code so the page loads quickly, watch which functions run often, and compile those hot spots into optimized machine code while the program runs. This is a big reason web apps today feel nearly as fast as installed software.

The practical takeaway: compiled and interpreted describe how a particular implementation runs code, not a fixed property of the language. What matters to you as a user is that, one way or another, everything ends up as machine instructions for your CPU.

Step 5 of 12Practice · Sort into groups

Sort each description into compiler or interpreter.

Tap an item, then tap its group (or drag it there).

Step 6 of 12Learn

Power button to desktop

When you press the power button, RAM is empty and the CPU has no program to run. The boot process solves this chicken-and-egg problem in stages:

  1. Power on: the power supply stabilizes and the CPU starts fetching instructions from a fixed address that points into a small chip of firmware, usually UEFI (older PCs used BIOS).
  2. Self-test: the firmware checks and initializes key hardware such as RAM, storage and the keyboard.
  3. Find a boot loader: the firmware looks on the configured drive for a small program called the boot loader. With Secure Boot, it first checks that the boot loader is digitally signed by a trusted maker, blocking some kinds of malware.
  4. Load the kernel: the boot loader copies the core of the operating system, the kernel, from storage into RAM and jumps to it.
  5. Start the system: the kernel sets up memory management, loads drivers for your hardware and starts system services.
  6. Log in: the login screen appears, then your desktop and startup apps.

On an SSD all of this commonly takes well under 30 seconds.

Step 7 of 12Practice · Put in order

Put these boot stages in order.

Drag the items, or use the arrow buttons, to put them in order.

  1. Firmware tests and initializes hardware
  2. Boot loader loads the kernel into RAM
  3. Firmware finds and checks the boot loader
  4. Login screen appears
  5. CPU begins running firmware code
  6. Kernel loads drivers and starts services

Step 8 of 12Diagram

Booting up

Booting upProcess diagram: Power on → Firmware (UEFI) → Self-test → Boot loader → OS kernel starts → Login and desktop.Power onFirmware (UEFI)Self-testBoot loaderOS kernel startsLogin and desktop

Tap a shape with to see more.

Power on
Firmware (UEFI)

Code on a chip, the only thing the CPU can run at first.

Self-test
Boot loader

Found on the drive; loads the OS kernel into RAM.

OS kernel starts
Login and desktop

Step 9 of 12Learn

What the operating system does for apps

Once running, the operating system (OS), such as Windows, macOS, Linux, Android or iOS, is the manager of the whole machine. Its main jobs:

  • Running programs: when you open an app, the OS loads its machine code from storage into RAM, gives it memory and starts it as a process.
  • Sharing the CPU: dozens of processes want to run. The OS switches between them many times per second, so they all appear to run at once.
  • Managing memory: each process gets its own private address space, so a crashing app can't scribble over another app's data.
  • Handling files and devices: apps ask the OS to read a file or play a sound; the OS talks to the hardware through drivers.
  • Security: user accounts, permissions and isolation decide what each program may touch.

Apps request these services through system calls, a controlled doorway into the kernel. A program never talks to the disk directly; it asks the OS, which checks permissions first. That separation is what keeps one buggy or malicious app from taking over the whole computer.

Step 10 of 12Note

Step 11 of 12Practice · Select all that apply

Which of these are jobs of the operating system? Select all that apply.

Select all that apply.

Step 12 of 12Practice · Choose one

Why can't a computer simply start running the operating system directly from RAM when it is switched on?