Pipeline Processor · Computer Organization and Architecture
53 questions · asked in 25 of 27 years (2000–2026)
MCQ 29 · MSQ 2 · NAT 221-mark 23 · 2-mark 30
2000Questions per year2026
Questions 31–35 of 53
A 5-stage pipelined processor has Instruction Fetch (IF), Instruction Decode (ID), Operand Fetch (OF), Perform Operation (PO) and Write Operand (WO) stages. The IF, ID, OF and WO stages take 1 clock cycle each for any instruction. The PO stage takes 1 clock cycle for ADD and SUB instructions, 3 clock cycles for MUL instruction, and 6 clock cycles for DIV instruction respectively. Operand forwarding is used in the pipeline. What is the number of clock cycles needed to execute the following sequence of instructions?
Answer: (B)
Only one instruction can be in the PO stage at a time. With forwarding, a result goes straight from the end of PO to the next instruction, so it does not wait for WO.
- I0 MUL: IF 1, ID 2, OF 3, PO 4 to 6, WO 7.
- I1 DIV: IF 2, ID 3, OF 4. PO is busy with MUL until cycle 6, so DIV waits and does PO in cycles 7 to 12, WO 13.
- I2 ADD: IF 3, ID 4, OF 5 (it waits behind DIV). It needs R5 from DIV, which is forwarded at the end of cycle 12, so PO is in cycle 13, WO 14.
- I3 SUB: IF 4, ID 5, OF 6 (it waits behind ADD). It needs R2 from ADD, forwarded at the end of cycle 13, so PO is in cycle 14, WO 15.
The last instruction finishes in cycle 15, so 15 cycles are needed.
Answer: (B)
- I0 MUL: IF 1, ID 2, OF 3, PO 4 to 6, WO 7.
- I1 DIV: IF 2, ID 3, OF 4. PO is busy with MUL until cycle 6, so DIV waits and does PO in cycles 7 to 12, WO 13.
- I2 ADD: IF 3, ID 4, OF 5 (it waits behind DIV). It needs R5 from DIV, which is forwarded at the end of cycle 12, so PO is in cycle 13, WO 14.
- I3 SUB: IF 4, ID 5, OF 6 (it waits behind ADD). It needs R2 from ADD, forwarded at the end of cycle 13, so PO is in cycle 14, WO 15.
The last instruction finishes in cycle 15, so 15 cycles are needed.
Answer: (B)
Consider a 4 stage pipeline processor. The number of cycles needed by the four instructions I1, I2, I3, I4 in stages S1, S2, S3, S4 is shown below:
What is the number of cycles needed to execute the following loop?
For (i=1 to 2) {I1; I2; I3; I4;}
What is the number of cycles needed to execute the following loop?
For (i=1 to 2) {I1; I2; I3; I4;}
Answer: (B)
Each stage handles one instruction at a time. We assume the buffers between stages can hold waiting results like a queue, so an instruction leaves a stage as soon as it is done. A stage of an instruction can start only when (1) the instruction has finished the previous stage and (2) the previous instruction has finished this stage. So
The loop runs I1 to I4 twice, so 8 instructions in all. The table shows the cycles each stage is busy.
For example, I3 finishes S1 in cycle 5, but S2 is busy with I2 until cycle 6, so I3 uses S2 in cycle 7. The last instruction leaves S4 at the end of cycle 23, so 23 cycles are needed.
Answer: (B)
The loop runs I1 to I4 twice, so 8 instructions in all. The table shows the cycles each stage is busy.
For example, I3 finishes S1 in cycle 5, but S2 is busy with I2 until cycle 6, so I3 uses S2 in cycle 7. The last instruction leaves S4 at the end of cycle 23, so 23 cycles are needed.
Answer: (B)
A non pipelined single cycle processor operating at 100 MHz is converted into a synchronous pipelined processor with five stages requiring 2.5 nsec, 1.5 nsec, 2 nsec, 1.5 nsec and 2.5 nsec, respectively. The delay of the latches is 0.5 nsec. The speedup of the pipeline processor for a large number of instructions is:
Answer: (C)
A single-cycle processor does a whole instruction in one clock, so its cycle time comes from the clock frequency:
In the pipelined processor the clock must fit the slowest stage plus the latch delay:
For a large number of instructions, in both cases, so
Answer: (C)
In the pipelined processor the clock must fit the slowest stage plus the latch delay:
For a large number of instructions, in both cases, so
Answer: (C)
Delayed branching can help in the handling of control hazards
The following code is to run on a pipelined processor with one branch delay slot:
I1: ADD R2 R7 + R8
I2 : SUB R4 R5 - R6
I3: ADD R1 R2 + R3
I4 : STORE Memory [R4] R1
BRANCH to Label if R1==0
Which of the instructions I1, I2, I3 or I4 can legitimately occupy the delay slot without any other program modification?
The following code is to run on a pipelined processor with one branch delay slot:
I1: ADD R2 R7 + R8
I2 : SUB R4 R5 - R6
I3: ADD R1 R2 + R3
I4 : STORE Memory [R4] R1
BRANCH to Label if R1==0
Which of the instructions I1, I2, I3 or I4 can legitimately occupy the delay slot without any other program modification?
Answer: (D)
The delay slot instruction runs whether the branch is taken or not, and it runs after the branch has read its condition. So the moved instruction must not change R1 (the branch condition), and the other instructions must not need its result.
(R2 = R7 + R8): reads R2. In the delay slot would run after , so would use the old R2 and compute a different R1. Cannot move.
(R4 = R5 - R6): uses R4 as its store address. In the delay slot would run after , so the store would go to the old R4 address. Cannot move.
(R1 = R2 + R3): the branch tests R1. In the delay slot would run after the branch has read R1, so the branch would test the old R1. Cannot move.
(store R1 to memory at R4): it changes no register, so the branch does not depend on it, and no later instruction needs its result. It only has to run once, and the delay slot runs it in both cases. So it can be moved after the branch into the delay slot.
Answer: (D)
(R2 = R7 + R8): reads R2. In the delay slot would run after , so would use the old R2 and compute a different R1. Cannot move.
(R4 = R5 - R6): uses R4 as its store address. In the delay slot would run after , so the store would go to the old R4 address. Cannot move.
(R1 = R2 + R3): the branch tests R1. In the delay slot would run after the branch has read R1, so the branch would test the old R1. Cannot move.
(store R1 to memory at R4): it changes no register, so the branch does not depend on it, and no later instruction needs its result. It only has to run once, and the delay slot runs it in both cases. So it can be moved after the branch into the delay slot.
Answer: (D)
Delayed branching can help in the handling of control hazards
For all delayed conditional branch instructions, irrespective of whether the condition evaluates to true or false
For all delayed conditional branch instructions, irrespective of whether the condition evaluates to true or false
Answer: (A)
A conditional branch can leave the pipeline waiting before the next instruction is known. To use this time, a delayed branch always executes the instruction placed right after the branch in memory (the delay slot). It runs whether the branch is taken or not, so the compiler puts there an instruction that is safe in both cases.
(A) is right: the instruction following the branch in memory is always executed.
(B) is not the rule: the delay slot is fixed by its position in memory, right after the branch, and it runs even when the branch is taken and control goes elsewhere.
(C) is wrong: the target instruction runs only after the delay slot, and only when the branch is taken.
(D) is wrong: the branch takes the same time as other instructions. The delay slot just hides the delay.
Answer: (A)
(A) is right: the instruction following the branch in memory is always executed.
(B) is not the rule: the delay slot is fixed by its position in memory, right after the branch, and it runs even when the branch is taken and control goes elsewhere.
(C) is wrong: the target instruction runs only after the delay slot, and only when the branch is taken.
(D) is wrong: the branch takes the same time as other instructions. The delay slot just hides the delay.
Answer: (A)
Keep practising