SECTION III-6: Internal Working of Computers

A step-by-step analysis of the process a CPU would go through to add three numbers is demonstrated below. Assume an imaginary CPU has registers called A, B. C, and D. It has an 8 bit of data bus and a 16 bit of address bus. Therefore, the CPU can access memory from addresses 0000 to FFFFH (for a total of 10000H locations). The action to be performed by the CPU is to put hexadecimal value 21 into register A, and then add to register A values 42H and 12H. Assume that the code for the CPU to move a value to register A is 1011 0000 (B0H) and the code for adding a value to register A is 0000 0100 (04H). The  steps to perform them are demonstrated below.


Action Code Data
Move value 21H into register A B0H 21H
Ass value 42H to register A 04H 42H
Add value 12H to register A 04H 12H


If the program to perform the actions listed above is stored in memory locations starting at 1400H, the following would represent the contents for each memory address location.


Memory Address Contents of Memory Address
1400 (B0) Code for moving a value to register A
1401 (21) Value to be moved
1402 (04) Code for adding a value to register A
1403 (42) Value to be added
1404 (04) Code for adding a value to register A
1405 (12) Value to be added
1406 (F4) Code for halt


The actions performed by the CPU to run the program above explained below:

  1.  The CPU's program counter can have a value between 0000 and FFFFH. The program counter must be set to the value 1400H, indicating the address of the first instruction code to be executed. After the program counter has been loaded with the address of the first instruction, the CPU is ready to execute.
  2. The CPU puts 1400H on the address bus and sends it out. The memory circuitry finds the location while the CPU activates the READ signal, indicating to memory that it wants the byte at location 1400H. This causes the contents of memory location 1400H, which is B0, to be put on the data bus and brought into the CPU.
  3. The CPU decodes the instruction B0 with the help of its instruction decoder dictionary. When it finds the definition for that instruction it knows it must bring into register A of the CPU the byte in the next memory location. It commands its controller circuitry to do exactly that. When it brings in value 21H from memory location 1401, it makes sure tha the doors of all registers are closed except register A. Therefore, when value 21H comes into the CPU it will go directly into register A. After completing one instruction, the program counter points to the address of the next instruction to be executed, which in this case is 1402H. Address 1402 is send our on the address bus to fetch the next instruction.
  4. From memory location 1402H the CPU fetches code 04H. After decoding, the CPU knows that it must add the byte sitting at the next address (1403) to the contents of register A. After the CPU brings the value, 42H, into register A, it provides the contents of register A along with this value to the ALU to perform the addition. It then takes the result of the addition from the ALU's output and puts it in register A. Meanwhile the program counter becomes 1404H , the address of the next instruction.
  5. Address 1404H is put on the address bus and the code is fetched into the CPU, decoded, and executed. This code again is adding a value to register A. The program counter and fetching instructions.

Now suppose that address 1403H contained value 04 instead of 42H. How would the CPU distinguish between data 04 to be added and code 04?. Code 04 for this CPU means "move the next value into register A". Therefore, the CPU will not try to decode the next value. It simple moves the contents of the following memory location into register A, regardless of its value.

More From