Processor Design: DataPath and Control

DataPath for a single cycle processor

The image above shows the datapath for a simple single-cycle CPU. The program counter feeds the instruction memory with an address and an instruction is generated. Part of the instruction is fed to the register file and determines which registers need to be accessed by the instrcution. The output of the register file is fed to the ALU and the result (if necessary) is passed to the date memory unit. In a bit more detail the datapath shown accomodates three types of instructions: Arithmetic/Logical Instructions, Memory Reference Instructions, Control Flow Instructions. The DataPath access for each type of instruction is as follows:

Obviously there needs to be some amount of control to make sure the ALU does the right operation, and the multiplexors allow the correct operand to propagate. The control logic is also derived from the instruction.

What is Wrong with a Single Cycle Implementation?

Since the clock cycle has to be the same length for every instruction, the clock cycle is dictated by the longest instruction. This happens to be a load instruction which accesses the instruction memory, the register file, the ALU, the data memory, and then register file, in that order. Brach instructions which only need to access the instruction memory, the register file, and the ALU will take just as long. A Multiple cycle implementation will use a single clock to drive each individual functional unit and each instruction takes a number of clock cycles equal to the number of functional units it utilizes.

Exceptions

The CPU described above functions assuming every instruction does something correct. However programs are often incorrect and thus we need to check for mistakes (i.e. illegal instructions, arithmetic overflow, etc.) and handle them. This is done using the exception mechanism. In a nutshell the exception mechanism is a piece of logic that determines that something went wrong and sets the PC to a predetermined address where the exception handler lives. The exception handler is a piece of software that saves the state of the machine (registers) and then services the exception. In many cases servicing an exception implies killing the program that generated it.