From Programmer Intent to CPU Circuits: ISA, Control Path, and Data Path

Today’s questions: 1. From the programmer’s intent to machine instructions. 2. From machine instructions to actual circuit behavior.

Picking up from the previous entry: the compiler compiles source code according to the ISA and chooses an implementation. Compilation essentially turns the complex operations described in a high-level language into combinations of basic machine instructions that the target CPU can execute. Through basic operations such as arithmetic, logic, data access (store/load), and control-flow transfers (conditional branches and jumps), these instructions work together to implement the program’s functionality. The CPU then executes them according to the semantics defined by the ISA.

For example, suppose we write int c = a + b at the source-code level. Our intent is to add a and b and assign the result to c. If all three variables are stored in memory, the compiler may choose this implementation at the ISA / machine-instruction level: 1. Load: read a and b from memory into registers. 2. Compute: calculate a + b using an addition instruction. 3. Store: write the result into c in memory. The CPU then executes the machine instructions to implement the behavior of c = a + b. After processing by the compiler and build tools, we obtain machine code or an executable program that can run in the target environment.

Why can the compiler and build tools produce machine code or an executable that runs in the target environment? After all, they do not negotiate with the CPU about what kind of machine code or executable to produce. It works because the compiler and CPU must follow the same ISA specification: the compiler generates code according to it, and the CPU hardware implements the execution effects it defines.

A question may arise: why load a and b from memory into registers, rather than a, b, and c? But why would we need to read C from memory? Our goal is simply to evaluate a + b and assign the final result to C. What was C’s original value? It does not participate in the computation at all.

Thus, assuming all three variables are stored in memory, the CPU can perform these steps:

StepCPU operationResult
1Read a and b from memoryRegisters t0=3, t1=5
2The ALU performs additionRegister t2=8
3Write t2 to the memory location corresponding to cc=8 in memory
Data flow: a=3 and b=5 move from memory into t0 and t1. The ALU adds them to produce t2=8, which is written back to c.

This explains an important distinction: A variable named C in the C language does not mean that the CPU must contain a register named C. C variables belong to the source-code level, while registers belong to the ISA and CPU level. The compiler establishes the correspondence between them.

II. The compiler translates the source code 'int c = a + b' into 'add t2, t0, t1'. This specifies: 1. Read data from t0 and t1. 2. Perform integer addition. 3. Write the result to t2. The core effect defined by the ISA is: t2←t0 + t1 (keeping the appropriate bits according to the destination register’s width). The ISA requires that t2 = 8 after this instruction executes. It usually does not specify how many logic gates the CPU uses internally, the structure of the adder, or how many clock cycles it takes to complete the operation. If the ISA only specifies the result of execution, what makes the hardware inside the CPU actually produce that result?

Now let’s move down from the ISA layer into the CPU’s hardware implementation. Inside the CPU are two parts with different functions that must work together. Control Path: decides which data to use, which operation to perform, and where to send the result. CU is the traditional collective name for its core control logic. Data Path: actually transfers data, performs computations, and ensures the result. It includes registers, the ALU, multiplexers, and other components.

Control and data paths inside the CPU: the CU controls register reads and writes and selects the operation. The register file supplies data to the ALU, whose result is written back to t2.

The key realization here is that the CU mainly generates control signals, while the data path performs the corresponding data operations according to those signals. This might make it sound as though the CU understands an instruction and then tells the ALU to perform addition. What actually happens is:

RISC-V instruction encoding: in a 32-bit instruction, different bit positions represent func, rs2, rs1, rd, opcode, or immediate fields.

A machine instruction is a group of bits. Bits at different positions are assigned to describe different information. The CU’s decoding logic recognizes these bits. When the instruction bits enter the decoding and control circuits, the circuits generate the corresponding control signals according to their already-designed logical relationships.

Both the CU and ALU use predesigned logic circuits to produce corresponding output signals from input signals. The difference is that their outputs serve different purposes. What these components can and cannot do is designed by people, in order to achieve the goals we want.

If we add another layer—the physical world: When designing the components, we establish that the corresponding input information will produce the corresponding physical effects.

Core questionCorresponding concept
1. What do I want the computer to do?Programming languages and their semantics
2. How do we turn this behavior into operations a machine can execute?The compiler and ISA
3. What does a machine instruction actually require the CPU to do?The ISA’s instruction semantics
4. Why can the CPU actually perform these operations?The CU, ALU, registers, data path, and digital circuits

Engineers design and manufacture circuit structures to realize a particular input–output relationship. When the circuit operates, physical laws determine how it responds to input signals. The ALU does not need to understand the mathematical symbol +. Its logic-circuit structure ensures that, under the design conditions, the corresponding binary input signals produce output signals that follow the rules of addition. Design intent explains why we build it. Circuit structure and physical laws explain why it can work.

The ISA (Instruction Set Architecture) is the dividing line: above it is the world of software (with variables, functions, and the concepts of addition, subtraction, multiplication, and division); below it is the world of physical circuits (with no numbers as such, only voltage levels and the movement of electrons). Going from C to the CPU’s internal hardware means translating a “specification” on paper into “physical causality” in the real world.