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 41–45 of 53
Following table indicates the latencies of operations between the instruction producing the result and instruction using the result.
Consider the following code segment:
What is the number of cycles needed to execute the above code segment assuming each instruction takes one cycle to execute?
Consider the following code segment:
Load R1, Loc 1; Load R1 from memory location Loc1
Load R2, Loc 2; Load R2 from memory location Loc 2
Add R1, R2, R1; Add R1 and R2 and save result in R1
Dec R2; Decrement R2
Dec R1; Decrement R1
Mpy R1, R2, R3; Multiply R1 and R2 and save result in R3
Store R3, Loc 3; Store R3 in memory location Loc 3 What is the number of cycles needed to execute the above code segment assuming each instruction takes one cycle to execute?
Answer: (C)
The code has 7 instructions, and each takes 1 cycle to execute. The latency in the table is the number of idle cycles that must lie between the producing instruction and the instruction using its result. For example, an ALU result used by another ALU operation needs 2 idle cycles in between.
So 13 clock cycles are needed in total.
Answer: (C)
- Load R1, Loc 1: no dependence, so it runs in T1.
- Load R2, Loc 2: no dependence, so it runs in T2.
- Add R1, R2, R1: uses R1 and R2, both from loads (Load to ALU latency 1). It must wait 1 cycle after I2, so it runs in T4. The wait after I1 is already covered.
- Dec R2: uses R2 from I2 (Load to ALU latency 1). It needs one idle cycle after T2, which is already there, so it runs in T5.
- Dec R1: uses R1 from I3 (ALU to ALU latency 2). I3 is in T4, so I5 cannot run before T7. I4 fills T5 and T6 is idle, so I5 runs in T7.
- Mpy R1, R2, R3: uses R1 from I5 (ALU to ALU latency 2), so it runs in T10. It also uses R2 from I4, which is satisfied by then.
- Store R3, Loc 3: uses R3 from I6 (ALU to Store latency 2), so it runs in T13.
So 13 clock cycles are needed in total.
Answer: (C)
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 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.
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
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
Answer: (B)
Each instruction needs the result of the one before it: R5 from ADD to MUL, R6 from MUL to SUB, R5 from SUB to DIV, and R6 from DIV to STORE.
With forwarding from EX to ID (split phase), a dependent instruction can decode in the same cycle in which its producer is in its last EX cycle, so it does not wait for WB. It must still wait for the producer's EX to finish, and MUL and DIV take 3 cycles in EX.
- ADD: IF 1, ID 2, EX 3, WB 4.
- MUL: ID in cycle 3 gets R5 from ADD's EX. EX is in cycles 4 to 6, WB 7.
- SUB: IF 3, then it stalls in cycles 4 and 5. It decodes in cycle 6, the last EX cycle of MUL, and gets R6. EX 7, WB 8.
- DIV: IF 6, ID 7 (gets R5 from SUB's EX), EX 8 to 10, WB 11.
- STORE: IF 7, stalls in cycles 8 and 9, ID 10 (gets R6 from DIV's EX), EX 11, WB 12.
The last WB is in cycle 12, so 12 cycles are needed.
Answer: (B)
With forwarding from EX to ID (split phase), a dependent instruction can decode in the same cycle in which its producer is in its last EX cycle, so it does not wait for WB. It must still wait for the producer's EX to finish, and MUL and DIV take 3 cycles in EX.
- ADD: IF 1, ID 2, EX 3, WB 4.
- MUL: ID in cycle 3 gets R5 from ADD's EX. EX is in cycles 4 to 6, WB 7.
- SUB: IF 3, then it stalls in cycles 4 and 5. It decodes in cycle 6, the last EX cycle of MUL, and gets R6. EX 7, WB 8.
- DIV: IF 6, ID 7 (gets R5 from SUB's EX), EX 8 to 10, WB 11.
- STORE: IF 7, stalls in cycles 8 and 9, ID 10 (gets R6 from DIV's EX), EX 11, WB 12.
The last WB is in cycle 12, so 12 cycles are needed.
Answer: (B)
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 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.
The number of Read-After-Write (RAW) dependencies, Write-After-Read( WAR) dependencies, and Write-After-Write (WAW) dependencies in the sequence of instructions are, respectively,
The number of Read-After-Write (RAW) dependencies, Write-After-Read( WAR) dependencies, and Write-After-Write (WAW) dependencies in the sequence of instructions are, respectively,
Answer: (C)
Let the instructions be I1 to I5 in order. A dependency between two instructions on the same register is:
- RAW: the later instruction reads a register that the earlier one writes.
- WAR: the later instruction writes a register that the earlier one reads.
- WAW: both write the same register.
We count a pair only when no instruction between them writes that register again. For example, I1 and I4 both use R5, but I3 rewrites R5 in between, so I4 depends on I3, not on I1.
RAW (4): I1 to I2 (R5), I2 to I3 (R6), I3 to I4 (R5), I4 to I5 (R6).
WAR (2): I2 reads R5 and I3 writes R5. I3 reads R6 and I4 writes R6.
WAW (2): I1 and I3 both write R5. I2 and I4 both write R6.
So the counts are 4, 2, 2.
Answer: (C)
- RAW: the later instruction reads a register that the earlier one writes.
- WAR: the later instruction writes a register that the earlier one reads.
- WAW: both write the same register.
We count a pair only when no instruction between them writes that register again. For example, I1 and I4 both use R5, but I3 rewrites R5 in between, so I4 depends on I3, not on I1.
RAW (4): I1 to I2 (R5), I2 to I3 (R6), I3 to I4 (R5), I4 to I5 (R6).
WAR (2): I2 reads R5 and I3 writes R5. I3 reads R6 and I4 writes R6.
WAW (2): I1 and I3 both write R5. I2 and I4 both write R6.
So the counts are 4, 2, 2.
Answer: (C)
A CPU has five-stages pipeline and runs at 1GHz frequency. Instruction fetch happens in the first stage of the pipeline. A conditional branch instruction computes the target address and evaluates the condition in the third stage of the pipeline. The processor stops fetching new instructions following a conditional branch until the branch outcome is known. A program executes instructions out of which 20% are conditional branches. If each instruction takes one cycle to complete on average, then total execution time of the program is
Answer: (C)
A branch instruction causes delay slots in the pipeline. The next instruction's IF starts only after the stage of the current instruction is done, which is during the stage.
Ideally, this should happen during the stage.
So, take the total number of instructions = , of which are branches.
This gives a penalty of cycles.
The clock speed is and each instruction takes cycle on average. So the total execution time in seconds is
Correct Answer:
Ideally, this should happen during the stage.
So, take the total number of instructions = , of which are branches.
This gives a penalty of cycles.
The clock speed is and each instruction takes cycle on average. So the total execution time in seconds is
Correct Answer:
We have two designs D1 and D2 for a synchronous pipeline processor. D1 has 5 pipeline stages with execution times of 3 nsec, 2 nsec, 4 nsec, 2 nsec and 3 nsec while the design D2 has 8 pipeline stages each with 2 nsec execution time How much time can be saved using design D2 over design D1 for executing 100 instructions?
Answer: (B)
Pipeline time = , where is the number of stages and is the number of instructions. The clock period is the slowest stage.
: , clock = max(3, 2, 4, 2, 3) = 4 ns, so time = (5 + 100 - 1) 4 = 416 ns.
: , clock = 2 ns, so time = (8 + 100 - 1) 2 = 214 ns.
Time saved = 416 - 214 = 202 ns.
Answer: (B)
: , clock = max(3, 2, 4, 2, 3) = 4 ns, so time = (5 + 100 - 1) 4 = 416 ns.
: , clock = 2 ns, so time = (8 + 100 - 1) 2 = 214 ns.
Time saved = 416 - 214 = 202 ns.
Answer: (B)
Keep practising