The silent page awaits the waking dawn.
int add(int a, int b) {
return a + b;
}mov eax, 10 ; 数据移动
add eax, 20 ; 整数加法
sub eax, 5 ; 整数减法
imul eax, ebx ; 整数乘法
and eax, ebx ; 按位与
cmp eax, ebx ; 比较
jmp target ; 无条件跳转if (a > b) {
return a;
}
return b;int add(int a, int b) {
return a + b;
}
The abstraction boundary between software and hardware
We normally write programs in high-level languages such as C, Java, Go, and Rust. These languages give you abstractions like variables, functions, loops, conditionals, and objects, so you never have to drive the processor directly.
But whatever language you use, the actual computation has to end up being done by the computer.
The problem is this: the CPU has no idea about the high-level languages we write.
The CPU doesn't understandint a = 10, nor does it directly execute a Java method or a Go function. What a processor can actually execute is a fixed set of predefined machine instructions.
So what exactly happens between a high-level language and execution on the CPU? Why can CPUs from different vendors run the same software? And why can't a program compiled for x86-64 usually be dropped onto an ARM processor and run?
To answer these questions, you first need to get to know one important concept: the instruction set architecture (Instruction Set Architecture, ISA).
1. From High-Level Language to Execution on the CPU
Here's a simple C program:
The logic here is straightforward: take two integers, add them, and return the result.
But to a CPU, this code has no executable meaning on its own. It has to be transformed by a compiler into machine instructions the processor can recognize.
Take x86-64, for example. Under the Linux System V AMD64 ABI, the compiler might generate assembly like this:
Here, rdi and rsi hold the first two integer arguments, eax holds the return value. lea normally computes an effective address, but the compiler can also use it to perform an integer addition; ret returns to the caller according to the calling convention.
What the CPU ultimately executes is not assembly text like lea and ret, but the corresponding binary machine code. For example, under a common encoding those two instructions correspond to:
Assembly is only one readable representation of machine instructions; the machine code is what the processor actually fetches and decodes.
This chain reveals a key point: between high-level languages and the CPU there has to be a set of machine-level rules that both sides follow. That rule set is the ISA.
2. ISA: The Contract Between Software and Processor
You can think of an ISA as a contract between the software and the processor.
On the software side, the rules defined by the ISA determine how machine instructions are generated; on the hardware side, the implementation has to realize those rules and guarantee that conforming instructions behave as specified.
For example, suppose the software wants to perform an integer addition:
That instruction doesn't describe how some particular CPU performs the addition internally. It states an observable semantic: add the values held in two registers, then update the destination register and related state as the instruction requires.
How the CPU gets there internally — which circuits it uses, how many clock cycles it takes, whether the work is split into several internal operations — is not specified directly by the ISA.
This is exactly what makes an ISA so valuable: it defines what the processor promises to the software, not how the processor must implement it.
2.1 What an ISA Actually Defines
An ISA is not just a list of instruction names. It usually defines a complete set of machine-level rules that are visible from outside.
Component
Main contents
Purpose
Instruction set
Arithmetic, data movement, jumps, logical operations, and so on
Defines which operations the processor can perform
Register model
Number of registers, their widths, purposes, and visible state
Defines which parts of the processor state instructions can operate on directly
Data types and widths
Integers, floating-point numbers, vector data, and so on
Defines how data is interpreted and computed on
Addressing modes
How to specify registers, memory addresses, and immediates
Defines how instructions access their operands
Memory model
Memory access ordering, atomic operations, and related constraints
Defines the visibility relationships among multiple memory operations
Exceptions and interrupts
Rules for handling divide-by-zero, page faults, illegal instructions, and similar situations
Defines the behavior software can observe when an exception occurs
Privilege mechanisms
Privilege levels, control registers, and protected operations
Lets the operating system manage processor resources
Together, these pieces define the machine-level environment that software can rely on.
2.2 The Instruction Set: What the Processor Can Do
The most intuitive part is the instruction set.
For example, x86-64 offers a large number of instructions in many different categories:
These aren't arbitrary operation names; they are machine-level operations with well-defined encodings, operand constraints, and execution semantics.
The compiler relies on exactly these capabilities to turn expressions, branches, and loops in a high-level language into sequences of instructions that the target ISA supports.
For example:
The compiler can turn that into a comparison plus a conditional jump:
The if in a high-level language is not a single fixed CPU instruction — it's a control flow that the compiler builds out of comparison, jump, and similar instructions.
2.3 The Register Model: The State the Processor Exposes to Software
Registers are very fast storage locations inside the processor. An ISA specifies which registers software can see and use, and what each of them is for.
In x86-64, for example, the common general-purpose registers include:
Register
Common uses
`rax`
General computation, function return value
`rbx`
General-purpose data storage
`rcx`
General computation, loop counters, and more
`rdx`
General computation, auxiliary register in some operations
`rsi`
General computation, function arguments
`rdi`
General computation, function arguments
`rsp`
Stack pointer
`rbp`
General computation, also commonly used for stack frame management
`rip`
Instruction pointer; indicates where the processor is currently executing
Registers are not merely an internal hardware detail. Because the ISA exposes them to software, the compiler has to know how many there are, how wide they are, and how they may be used in order to emit correct instructions.
One thing to keep in mind is that the exact role of a register in passing arguments is also constrained by the ABI (Application Binary Interface). The ISA defines the registers themselves, while the ABI goes further and specifies conventions such as how arguments are passed, where the return value goes, and which registers the caller or the callee is expected to preserve.
2.4 The Memory Model: Defining How Programs Observe Memory
A processor running a program can't rely on registers alone. Programs also need to reach variables, arrays, objects, and other data in memory.
An ISA specifies loads, stores, atomic operations, and the ordering constraints between different memory accesses.
For example:
The first instruction loads data from the memory address pointed to by rbx, and the second instruction stores the data at the memory address pointed to by rcx.
On a multicore processor, however, memory access ordering gets complicated. Different CPU architectures impose different constraints on the order of memory operations, and software has to follow the memory model of the architecture it targets to implement locks, atomic variables, and inter-thread communication correctly.
So an ISA defines not only how computation works, but also how software interacts with the memory system.
3. ISA vs. Microarchitecture: Rules Versus Implementation
Once you understand the ISA, you also need to distinguish another concept: the microarchitecture.
The two are often conflated, but they sit on different levels.
A simple analogy helps here: an ISA is like an interface specification that says which interfaces callers may use and what results those interfaces should produce; the microarchitecture is the concrete implementation behind those interfaces.
As long as a processor correctly implements the same ISA, software written for that ISA will run on it. Different processors can adopt completely different internal designs.
3.1 Same ISA, Very Different Performance
Suppose two processors both support x86-64.
They can differ in the following ways:
These differences affect how efficiently instructions execute, but they don't mean the two processors use different fundamental ISAs.
For instance, the same integer-addition instruction may be carried out by different execution units on different processors, with different latency and throughput. As long as the architecturally visible result matches what the ISA specifies, software never needs to know the internal implementation.
That lets processor vendors keep optimizing the hardware without changing the software interface.
3.2 An ISA Is Not a Processor Model
It is worth stressing that an ISA is not the name of any particular CPU.
For example:
The architecture defines the rules, the microarchitecture implements them, and a concrete processor product turns a microarchitecture into a chip.
4. Mainstream ISAs: x86, ARM, and RISC-V
The processor architectures in common use today are mainly x86, ARM, and RISC-V.
All three support general-purpose computing, but they differ in design philosophy, ecosystem, and target use cases.
4.1 x86 / x86-64
x86 was originally introduced by Intel and later grew into a vast compatibility ecosystem. x86-64 is the mainstream x86 architecture after the extension to 64 bits, also commonly called AMD64 or Intel 64.
Its typical characteristics include:
x86-64 is used pervasively in personal computers, servers, and cloud infrastructure.
4.2 ARM / AArch64
The ARM architecture has long been used in mobile devices, embedded systems, and low-power computing, and in recent years it has pushed into the personal computer and server markets as well.
AArch64 is the 64-bit execution state of the ARM architecture, and its characteristics include:
You need to distinguish the ARM architecture specification from concrete processor products. ARM supplies the architecture and processor IP, and chip vendors can design their own processors on the strength of a license.
4.3 RISC-V
RISC-V is an open instruction set architecture specification. It uses a modular design, combining a base instruction set with optional extensions to assemble different sets of capabilities.
Its characteristics include:
Open doesn't mean every RISC-V processor has the same capabilities. Which extensions a given processor supports still depends on its implementation and platform specification.
Architecture
Typical characteristics
Common domains
x86-64
Mature compatibility ecosystem, complex instruction encoding
PCs, servers
ARM AArch64
Strong low-power ecosystem, broad adoption
Phones, embedded systems, PCs, servers
RISC-V
Open specification, modular extensions
Education, embedded systems, custom chips
5. Why Programs for Different ISAs Can't Just Run
Now we can answer a very practical question: why can a program compiled on an x86-64 machine usually not be dropped onto an ARM64 device and run?
The reason is not that the operating systems necessarily differ, nor that the CPUs differ in performance, but that the encoding and semantics of the machine instructions may differ.
For example, both architectures have to perform an integer addition, but their instruction formats, operand positions, register numbering, and encoding rules are not the same.
The same source code can be turned into machine code for different architectures through different compiler backends, but the resulting binaries are not thereby interchangeable.
5.1 Source Code Can Cross Architectures; Machine Code Usually Can't
For example:
This C code doesn't depend on any particular ISA. As long as the target platform provides a suitable compiler and runtime environment, it can be compiled separately for x86-64, ARM64, or RISC-V.
But once compilation is done, the machine instructions in the object file have already been generated for one specific architecture.
So it's worth distinguishing:
5.2 The Operating System Is Part of Compatibility Too
Whether a program can run doesn't depend only on whether the CPU supports the corresponding ISA.
The operating system also has to provide the system calls, dynamic libraries, file formats, and runtime environment the program depends on.
For example, a Linux x86-64 program usually can't run directly on a Linux ARM64 system. Even when both systems run Linux, the differences in machine instruction architecture and application binary interface can't be ignored.
Running across architectures is possible with an emulator, dynamic binary translation, or a compatibility layer, but at that point the target CPU is no longer executing the original machine code directly.
6. Where an ISA Sits in Computer Architecture
Putting everything together, you get a complete chain of relationships:
Each layer in that chain carries a different responsibility:
An ISA matters because it decouples software from hardware.
Software doesn't need to know how many pipeline stages the CPU has or which branch-prediction algorithm it uses; hardware doesn't need to care whether the program was originally written in C or Rust. Both sides only have to honor the same machine-level contract.
7. Summary
An instruction set architecture is not a simple list of instructions; it is a complete machine-level specification the processor publishes to software.
It specifies which instructions the processor can execute, which registers software can see, how memory is accessed, and how exceptions and privilege mechanisms should work.
Understanding an ISA comes down to three ideas:
With these ideas in place, you have an entry point for looking at how a computer works underneath.
In the next article we'll keep going down the road from software to hardware: what steps does a program actually go through before it turns from source code into machine instructions the CPU can execute?