Components of the CPU
- Control Unit (CU): Checks the correctness of the sequence of operations. It fetches program instructions from memory, interprets them, and ensures correct execution of the program. It also controls input/output devices and directs the overall functioning of the other units of the computer.
- Arithmetic Logic Unit (ALU): Performs arithmetic operations (add and subtract) and logical operations (and, or) on the available data. Whenever an arithmetic or logical operation is to be performed, the required data is transferred from the memory unit to the ALU, the operation is performed, and the result is returned to the memory unit.
- Registers: Special storage locations with small memory space within the CPU that offer the advantage of fast speed. They work under the direction of the control unit to accept and hold data being processed. Registers are typically 8, 16, 32 or 64 bits wide (128 bits for very powerful computers), and are grouped into special purpose and general purpose registers.
Special Purpose Registers
- Accumulator (ACC): Collects the result of computations.
- Memory Address Register (MAR): Keeps track of where a given instruction or piece of data is placed/stored in memory.
- Memory Data Register (MDR): Holds data values.
- Program Counter (PC): Keeps the address of the next instruction to be executed.
- Instruction Register (IR): Holds the current instruction being executed.
General purpose registers, on the other hand, have no specific function; they are used according to the need of the program being executed.
The Machine Cycle (Fetch-Decode-Execute Cycle)
The machine or instruction cycle describes how machine instructions are repeatedly fetched, decoded and executed one at a time until an instruction to HALT is encountered. Before an instruction can be fetched, it must be placed into memory, along with related data, from an input or secondary storage device. Once the necessary data and instructions are in memory, the CPU performs the following four steps for each instruction:
- The control unit fetches data and instructions from memory.
- The control unit decodes the instruction, that is, determines what it means, and directs that the necessary data be moved to the arithmetic logic unit.
- The arithmetic logic unit executes the instruction on the data, performing the actual operation.
- The arithmetic logic unit stores the result of the operation in memory or in a register.
Steps 1 and 2 together are called the instruction time (I-time), while steps 3 and 4 are called the execution time (E-time). The combination of the I-time and the E-time is called the machine cycle. The length of time taken to fetch, decode and execute an instruction is measured in clock cycles.
