Fundamentals 27 min read

Fundamentals of Computer Architecture: CPU, Memory Hierarchy, Caches, and Compilation

This article explains the basic principles of computer architecture, covering CPU operation, memory hierarchy, cache levels, instruction sets, compilation, endianness, and related concepts such as simulators and operating system interactions, illustrating how simple instructions enable complex computations.

Top Architect
Top Architect
Top Architect
Fundamentals of Computer Architecture: CPU, Memory Hierarchy, Caches, and Compilation

The article introduces the fundamental concepts of computer architecture, starting with the historical development of computers and the universal model proposed by von Neumann in 1945, emphasizing that all computers execute simple instruction sequences.

CPU and Memory Basics : A computer consists of a processor (CPU) and memory (RAM). The CPU fetches instructions and data from RAM, executes operations, and stores results back. Memory is organized into addressable cells identified by binary addresses transmitted over signal lines.

Binary Representation : Bits are transmitted as voltage levels (high for 1, low for 0). Each memory cell typically stores one byte (8 bits). The article illustrates read and write modes with diagrams.

Instruction Set and Execution Cycle : The CPU executes a fetch‑decode‑execute cycle controlled by the program counter (PC). Simple example instructions are shown:

if x = 0
compute_this()
else
compute_that()

All software ultimately reduces to such primitive operations, whether for web browsers, games, or spreadsheets.

Endianness : Different CPUs store multi‑byte numbers in little‑endian or big‑endian order, affecting how binary sequences are interpreted.

Compilers : High‑level programming languages are translated by compilers into machine instructions. The article uses factorial examples to illustrate optimization:

function factorial(n)
if n > 1
return factorial(n - 1) * n
else
return 1

Optimized version:

function factorial(n)
result ← 1
while n > 1
result ← result * n
n ← n - 1
return result

Further compiler rewrites eliminate redundant calculations:

i ← x + y + 1
j ← x + y

and t1 ← x + y i ← t1 + 1 j ← t1

Operating Systems : Compiled programs rely on OS system calls to perform I/O, making binaries tied to both CPU architecture and OS. Consequently, a program compiled for Windows on x86 cannot run on macOS without recompilation.

Script Languages : Languages like JavaScript, Python, and Ruby are interpreted at runtime, offering rapid development at the cost of execution speed.

Reverse Engineering and Open Source : Binary programs can be disassembled to human‑readable instructions, enabling reverse engineering and security analysis. Open‑source software allows public inspection of source code, improving security transparency.

Memory Hierarchy : The article details the storage hierarchy—registers, L1/L2/L3 caches, RAM, secondary storage (SSD/HDD), and tertiary storage (tape/CD). Caches exploit temporal and spatial locality to reduce costly RAM accesses. Typical cache latencies: L1 ~10 CPU cycles, L2 ~100 cycles, RAM ~1000 cycles, SSD ~100 000 cycles, disk ~1 000 000 cycles.

Trends : While fast memory technology improves slowly, slower storage becomes faster and cheaper (SSD, hybrid drives). Efficient use of caches and minimizing RAM accesses remain key performance strategies.

Conclusion : By understanding CPU operation, memory hierarchy, instruction sets, and compilation, developers can design software that leverages hardware efficiently, achieving better performance across a wide range of computing platforms.

CompilationCPUComputer Architecturememory hierarchyInstruction setcachesendianness
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.