GATE 2015 (Session 2)
64 questions
MCQ 42 · NAT 221-mark 29 · 2-mark 35
Questions 51–55 of 64
Consider the C program below.
#include <stdio.h>
int *A, stkTop;
int stkFunc(int opcode, int val)
{
static int size=0, stkTop=0;
switch (opcode) {
case -1: size = val; break;
case 0: if (stkTop < size) A[stkTop++] = val; break;
default: if (stkTop) return A[--stkTop];
}
return -1;
}
int main()
{
int B[20]; A = B; stkTop = -1;
stkFunc (-1, 10);
stkFunc ( 0, 5);
stkFunc ( 0, 10);
printf ("%d\n", stkFunc(1, 0) + stkFunc(1, 0));
} The value printed by the above program is __________.Answer: 15
In stkFunc, the static local stkTop (it starts at 0) hides the global stkTop.
- stkFunc(1, 10) sets size = 10.
- Then 5 is pushed, and then 10 is pushed.
- The two pops return 10 and then 5.
The sum is 10 + 5 = 15.
Answer: 15
- stkFunc(1, 10) sets size = 10.
- Then 5 is pushed, and then 10 is pushed.
- The two pops return 10 and then 5.
The sum is 10 + 5 = 15.
Answer: 15
Consider the sequence of machine instructions given below:
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 ___________.
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 ___________.
Answer: 13
Cycle by cycle (PO handles one instruction at a time, and results are forwarded from PO):
- MUL: IF in 1, OF in 2, PO in 3-5, WB in 6
- DIV: IF in 2, OF in 3, PO in 6-10, WB in 11
- ADD: IF in 3, OF in 4, waits for R6, PO in 11, WB in 12
- SUB: IF in 4, OF in 5, waits for R7, PO in 12, WB in 13
Answer: 13
- MUL: IF in 1, OF in 2, PO in 3-5, WB in 6
- DIV: IF in 2, OF in 3, PO in 6-10, WB in 11
- ADD: IF in 3, OF in 4, waits for R6, PO in 11, WB in 12
- SUB: IF in 4, OF in 5, waits for R7, PO in 12, WB in 13
Answer: 13
Consider a processor with byte-addressable memory. Assume that all registers, including Program Counter (PC) and Program Status Word (PSW), are of size 2 bytes. A stack in the main memory is implemented from memory location and it grows upward. The stack pointer (SP) points to the top element of the stack. The current value of SP is . The CALL instruction is of two words, the first word is the op-code and the second word is the starting address of the subroutine (one word = 2 bytes). The CALL instruction is implemented as follows:
Store the current value of PC in the stack
Store the value of PSW register in the stack
Load the starting address of the subroutine in PC
The content of PC just before the fetch of a CALL instruction is . After execution of the CALL instruction, the value of the stack pointer is
Store the current value of PC in the stack
Store the value of PSW register in the stack
Load the starting address of the subroutine in PC
The content of PC just before the fetch of a CALL instruction is . After execution of the CALL instruction, the value of the stack pointer is
Answer: (D)
The stack grows upward, and SP points to the top element. So for each push, SP goes up by 2 first, and then the value is stored.
- Push PC: SP = 016E + 2 = 0170
- Push PSW: SP = 0170 + 2 = 0172
Answer:
- Push PC: SP = 016E + 2 = 0170
- Push PSW: SP = 0170 + 2 = 0172
Answer:
The number of min-terms after minimizing the following Boolean expression is _________.
Answer: 1
Reduce the expression inside the bracket step by step:
- Combine terms: , and then
- Next:
- Next:
The expression inside becomes . Its complement is ABCD, which is a single minterm.
Answer: 1
- Combine terms: , and then
- Next:
- Next:
The expression inside becomes . Its complement is ABCD, which is a single minterm.
Answer: 1
Let and A denote the area of the region bounded by f(x) and the x-axis, when x varies from -1 to 1. Which of the following statements is/are TRUE?
I) f is continuous in [-1,1]
II) f is not bounded in [-1,1]
III) A is nonzero and finite
I) f is continuous in [-1,1]
II) f is not bounded in [-1,1]
III) A is nonzero and finite
Answer: (C)
The function is not defined at x = 0 and becomes infinite there. So it is not continuous on [-1, 1] (I is false). It is also not bounded on [-1, 1] (II is true).
Statement III is about the area A between the curve and the x-axis. The function f is odd, so the signed integral from -1 to 1 would be 0. The area uses |f|, which is even, so the two halves add:
The area is finite and not zero (III is true).
Answer: (C)
Statement III is about the area A between the curve and the x-axis. The function f is odd, so the signed integral from -1 to 1 would be 0. The area uses |f|, which is even, so the two halves add:
The area is finite and not zero (III is true).
Answer: (C)