GATE 2005
203 questions
MCQ 2031-mark 203
Questions 86–90 of 203
Normally user programs are prevented from handling I/O directly by I/O instructions in them. For CPUs having explicit I/O instructions, such I/O protection is ensured by having the I/O instructions privileged. In a CPU with memory mapped I/O, there is no explicit I/O instruction. Which one of the following is true for a CPU with memory mapped I/O?
Answer: (A)
With memory mapped I/O the device registers sit at ordinary memory addresses, so a normal load or store instruction can reach a device. There is no I/O instruction to make privileged, so the protection must come from controlling which addresses a program may use.
The operating system does this. It maps the device address range only into kernel space and never into a user program's address space (using memory management and page protection). A user program cannot address a device, and it asks for I/O through a system call. The system call runs an OS routine in kernel mode, which does the I/O. So I/O protection is ensured by operating system routines.
(B) There is no special I/O instruction to trap on. What stops the access is the OS's control over which addresses a process can use.
(C) System configuration is done once. It cannot decide, for each running program, whether it may touch a device.
(D) Protection is possible, because the OS can keep device addresses out of user programs' reach.
Answer: (A)
The operating system does this. It maps the device address range only into kernel space and never into a user program's address space (using memory management and page protection). A user program cannot address a device, and it asks for I/O through a system call. The system call runs an OS routine in kernel mode, which does the I/O. So I/O protection is ensured by operating system routines.
(B) There is no special I/O instruction to trap on. What stops the access is the OS's control over which addresses a process can use.
(C) System configuration is done once. It cannot decide, for each running program, whether it may touch a device.
(D) Protection is possible, because the OS can keep device addresses out of user programs' reach.
Answer: (A)
Which one of the following is true for a CPU having a single interrupt request line and a single interrupt grant line?
Answer: (C)
A single interrupt request line can be shared by all devices. Their requests are joined (wired-OR), and any device can pull the line active. So multiple interrupting devices are possible.
The CPU answers with an interrupt acknowledge (INTA) on the single grant line. The grant line is passed from device to device in a daisy chain, so the first device in the chain that has requested takes the grant. That device then puts its own vector (or ISR address) on the data bus. The CPU uses it to jump to the right ISR. So vectored interrupts are possible as well.
Options A, B and D each say that one of these two is impossible, so they are wrong.
Answer: (C)
The CPU answers with an interrupt acknowledge (INTA) on the single grant line. The grant line is passed from device to device in a daisy chain, so the first device in the chain that has requested takes the grant. That device then puts its own vector (or ISR address) on the data bus. The CPU uses it to jump to the right ISR. So vectored interrupts are possible as well.
Options A, B and D each say that one of these two is impossible, so they are wrong.
Answer: (C)
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)
A 5 stage pipelined CPU has the following sequence of stages:
IF - Instruction fetch from instruction memory,
RD - Instruction decode and register read,
EX - Execute: ALU operation for data and address computation,
MA - Data memory access - for write access, the register read at RD stage is used,
WB - Register write back.
Consider the following sequence of instructions:
I1 : L R0, loc1; R0 <= M[loc1]
I2 : A R0, R0; R0 <= R0 + R0
I3 : S R2, R0; R2 <= R2 - R0
Let each stage take one clock cycle. What is the number of clock cycles taken to complete the above sequence of instructions starting from the fetch of I1 ?Answer: (A)
Stages: IF, RD, EX, MA, WB, one cycle each. I1 loads R0 from memory, I2 needs R0 from I1, I3 needs R0 from I2. I1 runs IF 1, RD 2, EX 3, MA 4, WB 5.
Without forwarding, a value can be used only after it is written back (WB) and then read (RD).
If WB and RD cannot share a cycle: I2 has RD 6, EX 7, MA 8, WB 9, and I3 has RD 10, EX 11, MA 12, WB 13. Total 13 cycles.
If WB writes in the first half of a cycle and RD reads in the second half (split-phase access), they can share a cycle: I2 has RD 5, EX 6, MA 7, WB 8, and I3 has RD 8, EX 9, MA 10, WB 11. Total 11 cycles.
Neither 13 nor 11 is among the options (8, 10, 12, 15), so the intended machine passes results between stages with operand forwarding.
With forwarding, a result goes straight to the EX stage of the next instruction without waiting for WB.
I1: the loaded value is ready only at the end of MA, cycle 4.
I2: IF 2, RD 3. Its EX needs R0, which is not ready until cycle 4 ends, so it waits one cycle (cycle 4). EX 5 (R0 forwarded from the MA of I1), MA 6, WB 7. The R0 read in RD is old, but that does no harm because EX uses the forwarded value.
I3: IF 3. It cannot move into RD in cycle 4 because I2 is still held there, so RD is 5. EX 6 (R0 forwarded from the EX of I2), MA 7, WB 8.
(The stage written MM in the figure is MA.) The last instruction finishes WB in cycle 8: 5 stages + 2 later instructions + 1 stall = 8 cycles.
Answer: (A)
Without forwarding, a value can be used only after it is written back (WB) and then read (RD).
If WB and RD cannot share a cycle: I2 has RD 6, EX 7, MA 8, WB 9, and I3 has RD 10, EX 11, MA 12, WB 13. Total 13 cycles.
If WB writes in the first half of a cycle and RD reads in the second half (split-phase access), they can share a cycle: I2 has RD 5, EX 6, MA 7, WB 8, and I3 has RD 8, EX 9, MA 10, WB 11. Total 11 cycles.
Neither 13 nor 11 is among the options (8, 10, 12, 15), so the intended machine passes results between stages with operand forwarding.
With forwarding, a result goes straight to the EX stage of the next instruction without waiting for WB.
I1: the loaded value is ready only at the end of MA, cycle 4.
I2: IF 2, RD 3. Its EX needs R0, which is not ready until cycle 4 ends, so it waits one cycle (cycle 4). EX 5 (R0 forwarded from the MA of I1), MA 6, WB 7. The R0 read in RD is old, but that does no harm because EX uses the forwarded value.
I3: IF 3. It cannot move into RD in cycle 4 because I2 is still held there, so RD is 5. EX 6 (R0 forwarded from the EX of I2), MA 7, WB 8.
(The stage written MM in the figure is MA.) The last instruction finishes WB in cycle 8: 5 stages + 2 later instructions + 1 stall = 8 cycles.
Answer: (A)
Consider line number 3 of the following C-program.
int main ( ) { /* Line 1 */
int I, N; /* Line 2 */
fro (I =0, I < N, I++); /* Line 3 */
} Identify the compiler's response about this line while creating the object-module:Answer: (A)
Line 3 is . The word is , not the keyword , and the three parts are separated by commas, not semicolons. So it is not a for loop header at all.
Lexical check: every piece is a valid C token: the identifier , brackets, the names , the number 0, and the operators and the commas. So there is no lexical error.
Syntax check: an identifier followed by brackets holding three comma-separated expressions (, , ), ending with a semicolon, is a valid function call statement. So there is no syntax error.
The function is not declared. In classic C, a call to an undeclared function is accepted: the compiler assumes it returns int, and at most gives a warning. The missing definition is found only when linking, not when the object module is created.
So the compiler reports no error for this line.
Answer: (A)
Lexical check: every piece is a valid C token: the identifier , brackets, the names , the number 0, and the operators and the commas. So there is no lexical error.
Syntax check: an identifier followed by brackets holding three comma-separated expressions (, , ), ending with a semicolon, is a valid function call statement. So there is no syntax error.
The function is not declared. In classic C, a call to an undeclared function is accepted: the compiler assumes it returns int, and at most gives a warning. The missing definition is found only when linking, not when the object module is created.
So the compiler reports no error for this line.
Answer: (A)