GATE 2008
185 questions
MCQ 1851-mark 52 · 2-mark 133
Questions 71–75 of 185
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)
(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)
For all delayed conditional branch instructions, irrespective of whether the condition evaluates to true or false
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)
I. Bypassing can handle all RAW hazards
II. Register renaming can eliminate all register carried WAR hazards
III. Control hazard penalties can be eliminated by dynamic branch prediction
Answer: (B)
II is true. A WAR hazard is a false dependence caused only by reusing a register name. Register renaming gives each write a new physical register, so a later write cannot overwrite a value that an earlier instruction still has to read.
III is false. Dynamic branch prediction only guesses the outcome. Each wrong guess still costs a flush of the pipeline, so the penalty is reduced, not eliminated.
The statements that are not true are I and III.
Answer: (B)
a = (x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z) Answer: (A)
Take option (A):
No
So skip the first part and look at the second part
Yes
the value of
Answer is (A)
void f (int n)
{
if (n <= 1) {
printf ("%d", n);
}
else {
f (n/2);
printf ("%d", n%2);
}
} Which of the following implementations will produce the same output for f(173) as the above code?P1
void f (int n)
{
if (n/2) {
f(n/2);
}
printf ("%d", n%2);
} P2
void f (int n)
{
if (n <=1) {
printf ("%d", n);
}
else {
printf ("%d", n%2);
f (n/2);
}
} Answer: (C)
The given code calls f(n/2) first and then prints . So the higher bits print first and it prints n in binary. For it prints n itself. Dividing 173 by 2 repeatedly gives 86, 43, 21, 10, 5, 2, 1. The remainders from the last call back are 1, 0, 1, 0, 1, 1, 0, 1, so f(173) prints .
P1 also calls f(n/2) before printing , but it stops when , that is for . For it prints , the same as the original. So P1 prints .
P2 prints before calling f(n/2), so it prints the bits from the lowest to the highest: and then the last call prints 1. The output is . This differs from , because the binary form of 173 is not a palindrome.
So only P1 gives the same output.
Answer: (C)