edited by
32,173 views
67 67 votes

A pipelined processor uses a 4-stage instruction pipeline with the following stages: Instruction fetch (IF), Instruction decode (ID), Execute (EX) and Writeback (WB). The arithmetic operations as well as the load and store operations are carried out in the EX stage. The sequence of instructions corresponding to the statement $X = (S - R * (P + Q))/T$ is given below. The values of variables $P, Q, R, S$ and $T$ are available in the registers $R0, R1, R2, R3$ and $R4$ respectively, before the execution of the instruction sequence.

$$\begin{array}{lll} 
\text{ADD} & R5, R0, R1 & \text{; } R5 \leftarrow R0 + R1 \\
\text{MUL} & R6, R2, R5 & \text{; } R6 \leftarrow R2 \times R5 \\
\text{SUB} & R5, R3, R6 & \text{; } R5 \leftarrow R3 - R6 \\ 
\text{DIV} & R6, R5, R4 & \text{; } R6 \leftarrow R5 / R4 \\
\text{STORE} & R6, X & \text{; } X \leftarrow R6
\end{array}$$

The IF, ID and WB stages take 1 clock cycle each. The EX stage takes $1$ clock cycle each for the ADD, SUB and STORE operations, and $3$ clock cycles each for MUL and DIV operations. Operand forwarding from the EX stage to the ID stage is used. The number of clock cycles required to complete the sequence of instructions is

  1. $10$
  2. $12$
  3. $14$
  4. $16$

6 Answers

Best answer
101 101 votes

$$\small \displaystyle \begin{array}{|c|c|c|c|c|c|c|c|c|c|c|c|c|} \hline &C_1&C_2&C_3&C_4&C_5&C_6&C_7&C_8&C_9&C_{10}&C_{11}&C_{12}\\\hline
\textbf{ADD}&\text{IF}&\text{ID}&{\color{green}{\underset{\boxed{1}}{\text{EX}}}}&\text{WB}&&&&&&&&\\\hline
\textbf{MUL}&&\text{IF}&{\color{green}{\underset{\boxed{1}}{\text{ID}}}}&\text{EX}&\text{EX}&{\color{green}{\underset{\boxed{1}}{\text{EX}}}}&\text{WB}&&&&&\\\hline
\textbf{SUB}&&&\text{IF}&\color{red}{-}&\color{red}{-}&{\color{green}{\underset{\boxed{1}}{\text{ID}}}}&{\color{green}{\underset{\boxed{1}}{\text{EX}}}}&\text{WB}&&&&\\\hline
\textbf{DIV}&&&&&&\text{IF}&{\color{green}{\underset{\boxed{1}}{\text{ID}}}}&\text{EX}&\text{EX}&{\color{green}{\underset{\boxed{1}}{\text{EX}}}}&\text{WB}&\\\hline
\textbf{STORE}&&&&&& &\text{IF}&\color{red}{-}&\color{red}{-}&{\color{green}{\underset{\boxed{1}}{\text{ID}}}}&\text{EX}&\text{WB}\\\hline \end{array} $$

$\color{red}{-}\quad\text{Stalls}$
$\color{green}{\boxed{1}} \quad \text{Operand forwarding from EX-ID using split phase}$

So, answer is 12.

Correct Answer: $B$

For more Clarity see this discussion https://gateoverflow.in/3623/gate-it-2006-question-79?show=138313#c138313

Reference

edited by
32 32 votes

answer = option D = $16$ cycles are required

1 flag:
✌ Edit necessary (Jordan T. Carter “Wrong answer”)
7 7 votes

Hi  , I have a very silly doubt here. 

Can we do the IF stage as I did ? because in other answers I could see , IF is also done after EX

amarVashishth 

srestha goel 

I have the confusion here that , IF stage of I4 instruction , can I start it in clock 4 ? because anyhow , ID should be started at  clock 7. or does IF also needs to start at clock 6 ?

Please clarify this doubt.

(N.B : please bear with my poor , illegible hand-writing )

edited by
5 5 votes
Hazards in computer architecture are events that cause delays in the pipeline and prevent an instruction from being executed in the designated clock cycle.

If there is no any types of hazard then :-

Number of clock cycles = K+n-1 , where K :  No. of stages, n: No. of instructions

                                       =4+5-1

                                        =8

There are 3 types of hazards in pipeline system : 1.Structural 2.Data 3.Control

Extra cycle due to hazards :-

1.Structural:  MUL and  DIV operations takes 3-1 = 2  extra cycles each i.e 2*2=4.

2.Data :  There is no extra cycles due to data hazard because of operand-forwarding(Given in question)

3.Control : Since, There is no branch instruction therefore no extra cycles due to control hazard

NOW,

The number of clock cycles required to complete the sequence of instructions is = 8+4 = 12.

Answer:
Position:
Show:

Related questions

64 64 votes
4 answers 4 answers
24.6k
24.6k views
Ishrat Jahan asked Nov 1, 2014
24,649 views
A pipelined processor uses a $4-$stage instruction pipeline with the following stages: Instruction fetch (IF), Instruction decode (ID), Execute (EX) and Writeback (WB). T...
78 78 votes
11 answers 11 answers
33.3k
33.3k views
go_editor asked Sep 28, 2014
33,275 views
Consider a $6$-stage instruction pipeline, where all stages are perfectly balanced. Assume that there is no cycle-time overhead of pipelining. When an application is exec...
197 197 votes
9 answers 9 answers
76.8k
76.8k views
Kathleen asked Sep 22, 2014
76,780 views
A $5$ stage pipelined CPU has the following sequence of stages:IF – instruction fetch from instruction memoryRD – Instruction decode and register readEX – Execute: ALU op...
74 74 votes
4 answers 4 answers
35.1k
35.1k views
Kathleen asked Sep 12, 2014
35,113 views
Which of the following are NOT true in a pipelined processor?Bypassing can handle all RAW hazardsRegister renaming can eliminate all register carried WAR hazardsControl h...