In this lesson, you will learn how to bridge the gap between your CPU’s instruction set and the hardware by connecting the Arithmetic Logic Unit (ALU) to the rest of the datapath using control signals.
Connecting the ALU to the Datapath
Up until now, we have treated the ALU as a standalone math block. In a functional CPU, however, the ALU sits at the heart of the datapath. It receives two inputs: usually a value from a register (read from the Register File) and either another register value or an immediate value (provided by the instruction decoder).
The ALU’s output doesn't just "appear"; it must be routed back to the register file or the memory system based on what the instruction requires. To coordinate this, we introduce Control Signals.
Defining Control Signals
The control unit examines the opcode of your instruction and sets the "ALU Control" lines. These lines tell the ALU which operation to perform (e.g., ADD, SUB, AND, OR). Without these signals, the ALU wouldn't know whether to treat a binary pattern as a request to sum two numbers or to compare them.
Consider a simple ADD R1, R2, R3 instruction:
- Instruction Fetch: The CPU fetches the machine code.
- Decode: The controller identifies this as an
ADDoperation. - Control Signal: The controller sets the ALU control lines to the specific bit pattern that triggers the
ADDlogic gate circuitry. - Execution: The ALU processes the values from
R2andR3. - Write Back: The result is placed on the result bus, destined for
R1.
[Register File] --> [ALU Input A]
--> [ALU] --> [Result Bus]
[Immediate/Reg] --> [ALU Input B]
|
[Control Unit (Opcode)] --> [ALU Control Signals]
By connecting the ALU to the datapath via these control signals, we transform a static collection of logic gates into a flexible machine capable of executing different commands based on the software instruction provided. The ALU acts as the "doer," while the control signals act as the "director," ensuring the right math happens at the right time.
Key Takeaway: The ALU is integrated into the datapath by routing operand sources to its inputs and using control signals from the instruction decoder to dictate which operation is performed on that data.