b_book1.gif (162 bytes) CPU & Memory
Basic | Advanced (using 80386)

CPU & Memory Interaction

In order to illustrate how the three main components of the Central Processing Unit interact i.e.; the Control Unit, the ALU and Memory, we will now look at how a CPU;
  • accepts keyboard input
  • multiplies two numbers
  • prints the result.

[Dual processor CPU]

(1). First Instruction

         [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |----------Primary Storage--------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7     |8    ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9     |10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||            |   |-----------|--------|------|-----||
||            |   |5 End      |6       |10    |11   ||
|+------------+   |           |        |      |     ||
|               | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(2). Request first number

          [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7     |8    ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9     |10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||            |   |-----------|--------|------|-----||
||            |   |5 End      |6       |10    |11   ||
|+------------+   |           |        |      |     ||
|               | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(3). Input first number

          [Keyboard]
+CPU------------Input--------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7 25  |8    ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9     |10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||            |   |-----------|--------|------|-----||
||            |   |5 End      |6       |10    |11   ||
|+------------+   |           |        |      |     ||
|               | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(4). Request second number

          [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7 25  |8    ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9     |10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||            |   |-----------|--------|------|-----||
||            |   |5 End      |6       |10    |11   ||
|+------------+   |           |        |      |     ||
|               | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(5). Input second number

          [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7 25  |8 40 ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9     |10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||            |   |-----------|--------|------|-----||
||            |   |5 End      |6       |10    |11   ||
|+------------+   |           |        |      |     ||
|               | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(6). CU issues multiply

          [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7 25  |8 40 ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9     |10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||            |   |-----------|--------|------|-----||
||            |   |5 End      |6       |10    |11   ||
|+------------+   |           |        |      |     ||
|               | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(7). ALU sets up multiplication

          [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7 25  |8 40 ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9     |10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||    25      |   |-----------|--------|------|-----||
||    40  x   |   |5 End      |6       |10    |11   ||
||            |   |           |        |      |     ||
|+------------+ | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(8). ALU performs multiplication

          [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7 25  |8 40 ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9     |10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||    25      |   |-----------|--------|------|-----||
||    40  x   |   |5 End      |6       |10    |11   ||
||  1000      |   |           |        |      |     ||
|+------------+ | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(9). Results to memory

          [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7 25  |8 40 ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9 1000|10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||    25      |   |-----------|--------|------|-----||
||    40  x   |   |5 End      |6       |10    |11   ||
||  1000      |   |           |        |      |     ||
|+------------+ | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(10). Print instruction

          [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7 25  |8 40 ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9 1000|10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||    25      |   |-----------|--------|------|-----||
||    40  x   |   |5 End      |6       |10    |11   ||
||  1000      |   |           |        |      |     ||
|+------------+ | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(11). Print result

          [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7 25  |8 40 ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9 1000|10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||    25      |   |-----------|--------|------|-----||
||    40  x   |   |5 End      |6       |10    |11   ||
||  1000      |   |           |        |      |     ||
|+------------+ | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]


(12). End instruction

          [Keyboard]
+CPU---------Input-----------------------------------+
| +---------+  v  |-----------Primary Storage-------||
| | Control |     |    Programs        |    Data    ||
| | Unit    | <-> |--------------------|------------||
| +---------+     |1 Enter    |2 Enter |7 25  |8 40 ||
|      ^          |  First    |  Second|      |     ||
|      v          |  Number   |  Number|      |     ||
|+------------+   |-----------|--------|------|-----||
|| Arithmetic |   |3 Multiply |4 Print |9 1000|10   ||
|| Logic Unit |<->|  1st & 2nd|  Result|      |     ||
||------------|   |  Numbers  |        |      |     ||
||    25      |   |-----------|--------|------|-----||
||    40  x   |   |5 End      |6       |10    |11   ||
||  1000      |   |           |        |      |     ||
|+------------+ | +---------------------------------+|
+------------Output----------------------------------+
                v
          [Printer]

Advanced (using Intel 80386)

[80386 CPU internals]

(Components explained below) [Ref][Ref 79,80]

Adding two numbers (summarised version follows)

Step 1

1. The prefetch unit asks the Bus Interface Unit to retrieve the instruction to add two numbers.
1.1. At the same time the segment and paging units convert the instruction's location from a virtual address to physical address, for the Bus Interface unit.

Step 2

The Bus Interface Unit gets the instruction from RAM and sends it to the prefetch unit.

Step 3

The Prefetch Unit forwards the instruction to the Decode Unit which forwards it to the Execution Unit.

Step 4

The Control Unit sends a virtual address of the first number to be added (stored in RAM) to the Protection Test Unit.

Step 5

The Protection Test Unit verifies that the control unit can access the first number and forwards it to the segment and paging units, where the virtual address is translated into a physical address for the bus interface unit.

Step 6

The Bus Interface unit retrieves the number stored at that address in RAM. This number then travels through the Protection Test Unit to the Execution Unit and is stored in one of the chip's internal registers.

Step 7

The second number undergoes a similar process.

Step 8

The Arithmetic Unit adds the second number retrieved from RAM and the first from the internal register.

Step 9

The Control unit tells the Bus interface unit to store the number in RAM. The Memory Management Unit translates the virtual address to a physical RAM address, completing the instruction.

Summarised

  1. Prefetch Unit gets an instruction from RAM and passes it to the Control unit (CU).
  2. CU gets first number from RAM and places it into a register.
  3. CU gets second number from RAM and places it into a register.
  4. CU directs the Arithmetic and Logic unit (ALU) to add the contents of the registers and puts the result into a register.
  5. CU sends the result to RAM.

Notes

[Rev: 25/1/98] 16/10/97 © 1997-98 V/2-Com (Verhaart), P O Box 8415, Havelock North, New Zealand.