From ISA to CPU: How an Addition Instruction Executes

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. Now let’s move down from the ISA layer into the CPU’s internal hardware implementation. First, the CPU fetches the instruction at the address held in the PC and places it in the IR. The CU decodes the instruction and generates control signals, determining what operation the ALU performs and whether the PC advances by 4 or jumps to a specified address, among other things. For example, here is a simplified process for the CPU executing add x3, x1, x2: 1. Fetch the instruction at the address specified by the PC and place it in the IR. 2. The CU reads the instruction in the IR and generates control signals: “Select x1 and x2 as the data sources, and select the ALU’s addition function.” 3. Write the result back to register x3. 4. Set PC=PC+4 and continue executing instructions.