Consider the following program segment for a hypothetical CPU having three user registers and
\begin{array}{|l|l|c|} \hline \text {Instruction} & \text{Operation }& \text{Instruction size (in Words)} \\\hline \text{MOV }
& \text{} \leftarrow \text{Memory}& \text{} \\\hline\text{MOV } & \text{} \leftarrow \text{Memory}& \text{} \\\hline \text{ADD } & \text{} \leftarrow \text{} & \text{} \\\hline \text{MOV } & \text{Memory} \leftarrow \text{} & \text{} \\\hline \text{Halt} & \text{Machine Halts} & \text{} \\\hline \end{array}
Let the clock cycles required for various operations be as follows:
\begin{array}{|l|l|} \hline \text {Register to/from memory transfer} & \text{3 clock cycles } \\\hline \text {ADD with both operands in register} & \text{1 clock cycles } \\\hline \text {Instruction fetch and decode} & \text{2 clock cycles }\\\hline \end{array}
The total number of clock cycles required to execute the program is
View worked solution
Answer: B
To find the total number of clock cycles required to execute the program, we need to calculate the cycles spent on Instruction Fetch & Decode and Execution for each instruction.
1. Instruction Fetch and Decode Cycles
Since the instruction sizes are specified in words, the fetch and decode operation must be performed for each word of the instruction. Thus, the fetch and decode cost is:
2. Execution Cycles
- Register to/from memory transfer: clock cycles
- ADD with both operands in registers: clock cycle
- Halt: additional execution cycles (only fetch and decode is needed to halt the machine)
Step-by-Step Calculation
| Instruction | Size (Words) | Fetch & Decode Cycles | Execution Cycles | Total Cycles |
|---|---|---|---|---|
MOV R1, 5000 |
2 | (Memory Register) | ||
MOV R2, (R1) |
1 | (Memory Register) | ||
ADD R2, R3 |
1 | (Register-to-Register ADD) | ||
MOV 6000, R2 |
2 | (Register Memory) | ||
Halt |
1 |
Summing the total cycles for all instructions:
Therefore, the correct option is B.
Free practice · Your answers on this page are not saved.
