edited by
29,728 views
79 79 votes

Consider the following program segment for a hypothetical CPU having three user registers $R_1, R_2$ and $R_3.$

$$ \begin{array}{|l|l|c|} 
\hline 
\text{Instruction} & \text{Operation} & \text{Instruction size (in Words)} \\
\hline 
\text{MOV } R_1, 5000 & R_1 \leftarrow \text{Memory}[5000] & 2 \\
\hline
\text{MOV } R_2, (R_1) & R_2 \leftarrow \text{Memory}[(R_1)] & 1 \\
\hline 
\text{ADD } R_2, R_3 & R_2 \leftarrow R_2 + R_3 & 1 \\
\hline 
\text{MOV } 6000, R_2 & \text{Memory}[6000] \leftarrow R_2 & 2 \\
\hline 
\text{Halt} & \text{Machine Halts} & 1 \\
\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

  1. $29$
  2. $24$
  3. $23$
  4. $20$

6 Answers

Best answer
152 152 votes

B.  $24 \text{ cycles}$

$$\begin{array}{|l|c|c|} \hline \text {Instruction}  &  \text{Size }& \text{Fetch and Decode + Execute} \\\hline \text{MOV} & \text{$2$} & \text{$2$} \times \text{$2 + 3 = 7$} \\\hline  \text{MOV} & \text{$1$} & \text{$2$} \times \text{$1 + 3 = 5$} \\\hline  \text{ADD} & \text{$1$} & \text{$2$} \times \text{$1 + 1 = 3$} \\\hline \text{MOV} & \text{$2$} & \text{$2$} \times \text{$2 + 3 = 7$} \\\hline \text{HALT} & \text{$1$} & \text{$2$} \times \text{$1 + 0 = 2$} \\\hline   & \text{Total} & \text{$24 $ Cycles} \\\hline \end{array}$$

edited by
57 57 votes
Each instructions requires fetch and decode

So total instructions size is 7 words

Number of cycles = 7*2=14 cycles

Now in addition to that

Move     R1,5000 3 cycles for register /to memory transfer

Move     R2,(R1)  3 cycles

Add        R2,R3    1 cycle ALU

Move     6000,R2  3 cycle

Additional 10 cycle

Total = 14+10=24 cycles
edited by
11 11 votes

The clock cycles are per block; if an instruction size is 2 then it requires twice no. of clock cycles.

Instruction no.       size                                              no. of clock cycles
1                                2                                                                       3*2+2
2                                1                                                                       1*3+2
3                                1(add only)                                                      1
4                                2                                                                       3*2+2
5                                1                                                                       2(fetch and decode)
                                Total                                                                  24

  So answer is (B)

5 5 votes
$3+3+1+3+7(2)=24$

Why the Instruction Fetch and Decode is counted 7 times when the number of instructions are 5?

Because the largest unit of memory that can be transferred to and from it, in a single operation is the word size. Since there are 7 words in total, to fetch them we need to devote 7 separate operations, and each such operation would take 2 clock cycles (given)
1 1 vote

 


Given:

  • Instruction fetch + decode = 2 cycles    Register ↔ Memory transfer = 3 cycles      ADD with both operands in registers = 1 cycle

Instructions and sizes:

InstructionOperationSize (words)
MOV R1, 5000R1 ← Memory[5000]2
MOV R2, (R1)R2 ← Memory[(R1)]1
ADD R2, R3R2 ← R2 + R31
MOV 6000, R2Memory[6000] ← R22
HaltMachine halts1

Step 1: Instruction fetch & decode

  • Instruction size matters only for fetch, because CPU fetches each word separately.

  • Each word fetch = 2 cycles

Instruction 1: MOV R1, 5000 (2 words)

  • Fetch word 1: 2 cycles

  • Fetch word 2: 2 cycles

  • Memory transfer (R1 ← Memory[5000]): 3 cycles


  • Total = 2 + 2 + 3 = 7 cycles


Instruction 2: MOV R2, (R1) (1 word)

  • Fetch: 2 cycles

  • Memory transfer (R2 ← Memory[(R1)]): 3 cycles
    Total = 2 + 3 = 5 cycles


Instruction 3: ADD R2, R3 (1 word)

  • Fetch: 2 cycles

  • ADD (register operands): 1 cycle


  • Total = 2 + 1 = 3 cycles


Instruction 4: MOV 6000, R2 (2 words)

  • Fetch word 1: 2 cycles

  • Fetch word 2: 2 cycles

  • Memory transfer (Memory[6000] ← R2): 3 cycles


  • Total = 2 + 2 + 3 = 7 cycles


Instruction 5: Halt (1 word)

  • Fetch: 2 cycles

  • No other operation


  • Total = 2 cycles


Step 2: Add all cycles


7 + 5 + 3 + 7 + 2 = 24 


 Answer: B. 24

 

Answer:
Position:
Show:

Related questions

89 89 votes
5 answers 5 answers
43.5k
43.5k views
Kathleen asked Sep 18, 2014
43,462 views
Consider the following program segment for a hypothetical CPU having three user registers $R_1, R_2$ and $R_3.$ $$\begin{array}{|l|l|c|} \hline \text {Instruction} & \t...
54 54 votes
5 answers 5 answers
28.1k
28.1k views
Kathleen asked Sep 18, 2014
28,147 views
A 4-stage pipeline has the stage delays as $150$, $120$, $160$ and $140$ $nanoseconds$, respectively. Registers that are used between the stages have a delay of $5$ $nano...
82 82 votes
11 answers 11 answers
41.6k
41.6k views
Kathleen asked Sep 18, 2014
41,562 views
A hard disk with a transfer rate of $10$ Mbytes/second is constantly transferring data to memory using DMA. The processor runs at $600$ MHz, and takes $300$ and $900$ clo...
51 51 votes
2 answers 2 answers
19.8k
19.8k views
Kathleen asked Sep 18, 2014
19,780 views
The microinstructions stored in the control memory of a processor have a width of $26$ bits. Each microinstruction is divided into three fields: a micro-operation field o...