Monday, April 25, 2011

How the Central Processing Unit (CPU) Works

How the Central Processing Unit (CPU) Works

Computers and Society: How the Central Processing Unit (CPU) Works

The Central Processing Unit, or CPU, is where a computer does calculations. The figure below shows a simplified diagram of a CPU.



The memory and monitor are outside of the CPU. The memory locations are numbered, starting at zero, so they can be addressed by the CPU. Both data and program instructions are stored in the memory. Inside the CPU are the following features:
  • The Instruction Register (IR) is where the current program instruction is stored;
  • The Program Counter (PC) is the memory location where the current program instruction is stored;
  • The Accumulator (AC) is the place where the CPU processes data. The accumulator stores the results of calculations, and also has the hardware circuits to do addition, multiplication, and all of the other processing that the CPU is capable of;
  • Not shown is the Program Logic Unit (PLU), which sequences the operation of the CPU.
Under the direction of the PLU, the CPU follows the following cycle, repeatedly:
  1. FETCH the instruction from the memory location pointed to by the PC, and copy it to the IR;
  2. INTERPRET the instruction in the IR by deciding which calculation circuits to use;
  3. INCREMENT the PC to point to the next memory location;
  4. EXECUTE the instruction in the IR, using the circuits selected in the INTERPRET step. In the case of a "Go To" or "If" statement, the value in the PC can be changed, causing the program to go to another memory location;
  5. If the instructions was not a STOP instruction, return to Step 1 and continue.
The IR has two parts;
  1. The "Operation Code" or Op Code, a binary number which tells whether to add, subtract, divide, multiply, or some other operation;
  2. The memory location of the data to be used.
This is shown in the figure below.



Here is an example of how all of these parts work together. In this example, the programmer has the computer add the two numbers in memory locations 10 and 11, and put the answer in location 12. The program starts at location 0, which is the first or lowest-numbered memory location; the memory location of the instruction is the left-most column.
  1. GET the number stored in memory location 10 and copy it to the AC;
  2. ADD the number stored in memory location 11 and add it to the AC;
  3. STORE the contents of the accumulator in memory location 12;
  4. STOP.
Notice that a human would just add the two numbers in a single operation; but that the computer has to break this down into several steps.




Comments: