GATE CS 2015 Set 2 — Question 53
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.NAT+2 / -0MediumData ForwardingInstruction PipeliningComputer Organization & ArchitecturePipeline StallsPipeline Stages & Throughput
Computer Organization & Architecture → Instruction Pipelining → Data Forwarding
Last updated
Question
Consider the sequence of machine instructions given below:
In the above sequence, R0 to R8 are general purpose registers. In the instructions shown, the first register stores the result of the operation performed on the second and the third registers. This sequence of instructions is to be executed in a pipelined instruction processor with the following 4 stages: (1) Instruction Fetch and Decode (IF), (2) Operand Fetch (OF), (3) Perform Operation (PO) and (4) Write back the result (WB). The IF, OF and WB stages take 1 clock cycle each for any instruction. The PO stage takes 1 clock cycle for ADD or SUB instruction, 3 clock cycles for MUL instruction and 5 clock cycles for DIV instruction. The pipelined processor uses operand forwarding from the PO stage to the OF stage. The number of clock cycles taken for the execution of the above sequence of instructions is ___________.
MUL R5, R0, R1
DIV R6, R2, R3
ADD R7, R5, R6
SUB R8, R7, R4
In the above sequence, R0 to R8 are general purpose registers. In the instructions shown, the first register stores the result of the operation performed on the second and the third registers. This sequence of instructions is to be executed in a pipelined instruction processor with the following 4 stages: (1) Instruction Fetch and Decode (IF), (2) Operand Fetch (OF), (3) Perform Operation (PO) and (4) Write back the result (WB). The IF, OF and WB stages take 1 clock cycle each for any instruction. The PO stage takes 1 clock cycle for ADD or SUB instruction, 3 clock cycles for MUL instruction and 5 clock cycles for DIV instruction. The pipelined processor uses operand forwarding from the PO stage to the OF stage. The number of clock cycles taken for the execution of the above sequence of instructions is ___________.
Correct answer
13 to 13
Solution
The program demonstrates variable scoping rules in C, specifically the difference between global variables and static local variables.
1.Global Variables:
int *A, stkTop; are declared globally.2.Function
stkFunc:-
static int size=0, stkTop=0;declares static local variables. The localstkTopshadows the globalstkTopwithin this function. Static variables retain their values between function calls. - Opcode -1: Sets
size = val. - Opcode 0: Pushes
valonto the stack (arrayA) ifstkTop < size, incrementing the localstkTop. - Default: Pops from the stack if
stkTop > 0, returningA[--stkTop].
main:-
int B[20]; A = B; stkTop = -1;initializes arrayB, points globalAtoB, and sets globalstkTopto -1. Note that setting globalstkTophas no effect onstkFuncbecausestkFuncuses its own staticstkTop.
1.
stkFunc(-1, 10):-
opcodeis -1. - Static
sizebecomes 10. - Static
stkTopremains 0.
stkFunc(0, 5):-
opcodeis 0. -
stkTop(0) <size(10). -
A[0] = 5. - Static
stkTopbecomes 1.
stkFunc(0, 10):-
opcodeis 0. -
stkTop(1) <size(10). -
A[1] = 10. - Static
stkTopbecomes 2.
printf("%d\n", stkFunc(1, 0) + stkFunc(1, 0)):- Evaluate first
stkFunc(1, 0): -
opcodeis 1 (default case). -
stkTopis 2 (true). - Returns
A[--stkTop]A[1]which is 10. - Static
stkTopbecomes 1. - Evaluate second
stkFunc(1, 0): -
opcodeis 1 (default case). -
stkTopis 1 (true). - Returns
A[--stkTop]A[0]which is 5. - Static
stkTopbecomes 0. - Sum: .
Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE CS question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on Instruction Pipelining
2026 Set 1 Q14Match each addressing mode in List I with a data element or an element of a data structure (in…2026 Set 1 Q15Consider a processor P whose instruction set architecture is the load-store architecture. The…2026 Set 1 Q16Which one of the following dependencies among the register operands of different instructions can…2026 Set 2 Q18Consider the following two statements about interrupt handling mechanisms in a CPU. S1: In…2026 Set 1 Q38The size of the physical address space of a processor is bytes. The capacity of a cache…