How a CPU runs an instruction
The CPU fetches bits from memory, decodes them, runs them in the ALU, then writes results and advances the PC.
Published here , updated · 5 sources · Resume reading
Your program becomes a file of machine instructions. The CPU's job is a loop: fetch one instruction from memory, decode it, execute it, store the result, then move on [1]. Part 2 of this lane is pipelining and why CPUs speculate.
Quick start (under a minute)
You do not need silicon in your hands to see instruction bytes. Compile a tiny C function and disassemble it:
echo 'int add_two(int a){ return a+2; }' > /tmp/t.c
cc -c -O0 -o /tmp/t.o /tmp/t.c
objdump -d /tmp/t.o | head -n 20You should see mnemonic lines (mov, add, ret on x86-64, or add/ret on AArch64) each tied to hex opcodes [2]. Those lines are what the CPU eventually fetches after the OS loads the executable into RAM [1].
Load the executable into memory first
OpenStax: high-level code is translated into instructions stored as 1s and 0s in an executable. When you run a program, the OS loads that executable into main memory so the CPU can fetch from RAM instead of waiting on disk for every byte [1]. The loader also sets up the initial program counter and stack pointer per the ABI. Related memory picture: stack vs heap memory.
The single-cycle instruction loop (teaching picture)
Teaching texts collapse real hardware into a loop you can draw on a napkin [1]:
Real cores add caches, TLBs, and multiple execution units. The loop still names the work each retired instruction does [1] [3].
Walk the five beats in plain words
OpenStax's hardware story orders the beats like this [1]:
- Fetch: bring the next instruction from the address in the program counter into an instruction register.
- Decode: interpret the bit pattern (for example "add register x and y, store in z").
- Execute: the ALU (and specialized units) perform the operation.
- Write back: save the result in a register or memory location.
- Advance: update the program counter so execution continues in program order unless control flow changes.
Branches and calls rewrite step 5: the "next" address is not always PC plus the instruction length [2]. A conditional branch compares flags from the ALU and may select a taken target encoded in the instruction.
Meet the program counter and PC updates
OpenStax 5.4: the program counter (PC) keeps the address of the next instruction and is updated after each instruction so execution continues in sequence unless control flow changes [2]. On x86, instruction lengths vary; the CPU adds the decoded length, not a fixed word size. That detail matters when you debug corruption: a wrong return address is a wrong PC.
Worked example: disassembly output you can compare
On this draft host (Ubuntu 24.04, GCC 13, x86-64, -O0, 2026-12-03), the add function disassembly begins like:
/tmp/t.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <add_two>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 89 7d fc mov %edi,-0x4(%rbp)
7: 8b 45 fc mov -0x4(%rbp),%eax
a: 83 c0 02 add $0x2,%eax
d: 5d pop %rbp
e: c3 retReading left to right on one line: address, hex bytes, mnemonic [2]. At runtime the CPU fetches those bytes from the .text section in order until ret redirects control. Optimizing compilers reorder and elide instructions; always disassemble the build you profile.
If objdump is missing, install binutils per your distro docs. The pedagogy does not depend on one vendor ISA.
Where memory fits in the same cycle
Loads and stores move data between registers and addresses computed from base plus offset [1]. Those addresses may hit L1 cache in a few cycles or DRAM in hundreds. Contiguous layouts keep more useful bytes per cache line than pointer chasing; see arrays vs linked lists.
Why pipelines come next
OpenStax 5.6 splits the bulky single-cycle box into phases (fetch, decode, issue, execute, commit) so different instructions can occupy different phases at once [3]. Instruction i+1 may decode while instruction i executes. Throughput rises toward one instruction per cycle per pipeline slot when the program is predictable.
When the next PC is unknown (taken branch, indirect call), the front end may guess so the pipe stays full. Wrong guesses waste work; details and safety fences live in pipelining and why CPUs speculate.
Endianness shows up at the fetch boundary: the same 32-bit word in memory may list bytes differently in a hexdump versus register display [2]. The CPU still decodes according to the ISA. Cross-endian bugs appear at I/O boundaries, not in everyday add instructions on one machine.
Interrupts and traps also enter through the same machine: an external device or a faulting load can redirect the PC into a handler after the current instruction retires or is aborted per the architecture rules [1]. From the programmer's seat that still looks like "the CPU ran instructions"; the difference is who chose the next address. Kernel entry paths, syscall stubs, and page-fault handlers are ordinary instruction streams once fetch resumes at the vector [1] [2].
More reader questions
What is the ALU? The arithmetic logic unit performs integer math and bitwise ops on register operands named by the decoded instruction [1].
Where do operands live during execute? In registers when possible; load and store instructions move data between registers and memory addresses [1] [2].
Branches retarget the PC; a wrong return address is a wrong PC. That is why crash dumps lead with a faulting instruction pointer before anyone argues about high-level frameworks [2].
Do not do these
Thinking the CPU "runs Python." CPython, Node, and the JVM translate or interpret to machine code or internal bytecode with runtime helpers [1]. The silicon still ends up in this fetch/decode/execute loop for the native pieces.
Inlining, loop unrolling, and SIMD widen the gap between your editor view and retired instructions [2].
Decode maps bits to control signals. Meaning lives in your source and debug symbols.
Ignoring the PC on crashes. Segfaults and illegal instructions often show a faulting PC in a core dump. That address is where fetch or execute failed.
Treating all instructions as equal cost. Multiply, divide, floating point, and memory misses stall different pipeline stages [3].
Trace one add in your head: where the bytes came from, which register changed, what memory might update. Pipelining and speculation deepen that picture in CPU pipelining and why CPUs speculate; how main memory feeds the core is what is RAM (computer memory). For how managed runtimes reclaim heap after those allocations, see how garbage collection works.
When you read objdump -d output, match each mnemonic back to the fetch-decode-execute sketch above before you chase microarchitecture folklore.
Send this to the friend who writes JavaScript all day and has never pictured fetch and decode.

Keep this guide
Filed under Science, Dev explainers
Questions about this guide
What is the instruction cycle?
OpenStax describes fetching an instruction from memory into the CPU, decoding the bit pattern, executing it (often in the ALU), saving the result, then fetching the next instruction.
What is the program counter?
A register that holds the address of the next instruction. After a normal instruction, the CPU updates the PC so the next fetch continues in sequence unless a branch says otherwise.
What is the instruction register?
OpenStax places the fetched instruction bits in an instruction register (IR) before decode. The decode stage interprets opcode and operand fields.
Why do we talk about pipelines next?
OpenStax 5.6 splits fetch, decode, issue, execute, and commit so hardware can overlap work on different instructions. That story continues in the pipelining post.
Do high-level languages run directly on the CPU?
No. OpenStax notes HLLs are translated into machine instructions (1s and 0s) in an executable the OS loads into memory before the CPU runs them.
Sources
- Full Byte Developer: Pipelining and why CPUs speculatefullbytedeveloper.com
- Full Byte Developer: Stack vs heap memoryfullbytedeveloper.com