Step by step explanation of Example of Program Execution (contents of memory and registers in hexadecimal) in Computer Architecture
In this tutorial, we have two numbers 3 and 2 and we will add these two numbers. For example;
3+2=5. Now lets see step by step that how all this process will complete inside memory and CPU reigsters.
Opcodes and their meanings
Suppose that we have 16 bits, then the first 4 bits represent opcode, and the remaining 12 bits represent the address of the instruction.
- 0001= 1 = Load AC (accumulator) from memory
- 0010= 2 = Store AC (accumulator) to Memory
- 0101= 5 = Add to AC from Memory
For example, instruction 1940 is on address 300, its leftmost number is 1, so we take it as an opcode for the instruction. 1 means to Load AC (accumulator) from memory
Explanation of diagram
First, we loaded three instructions on memory.
- 1940 on address 300
- 1 is opcode to Load AC (accumulator) from memory
- 940 is address and value of 003 is on this address
- 5941 on address 301
- 5 is opcode to Add to AC from Memory
- 941 is address and value of 002 is on this address
- 2941 on address 302
- 2 is opcode to Store AC (accumulator) to Memory
- 941 is addressed and the value of 002 is on this address at the start and after execution of the complete program, it is updated with 5.
The operating system helps the PC Register to decide which instruction will be executed now. The operating system can decide it according to the scheduling algorithms. If you remember in the operating system course, you have learned some special techniques of process scheduling. For example;
- First come first served scheduling
- Priority Scheduling
- Shortest Job first scheduling
- Round Robin Scheduling etc.
In this example PC register allows instruction on address 300, when this instruction completes, then the PC register allows to instruction on address 301, and when this instruction completes, then the PC register allows instruction on address 302
The PC register allows an instruction, and then send this instruction to the MAR register. MAR register is the memory address register.
With the help of the MAR register, the MBR register buffers the instruction. MBR register is the memory buffer register.
The IR register is the instruction register. IR Register tells the CPU which instruction is being executed.
The AC register is the accumulator register. The AC register helps to temporarily store the values.