GATE 2006
191 questions
MCQ 1911-mark 191
Questions 86–90 of 191
Which of the following DMA transfer modes and interrupt handling mechanisms will enable the highest I/O band-width?
Answer: (C)
I/O bandwidth depends on how long the DMA can keep the bus (the DMA mode) and how fast the CPU reacts to the device (the interrupt method).
DMA mode:
- Transparent DMA uses the bus only when the CPU is not using it. The CPU is never slowed, but the device must wait for free bus time, so the I/O rate is low. This makes (A) wrong.
- In cycle stealing the device moves one word, gives the bus back, and gets it again only after a few CPU cycles. So the I/O rate is limited. This makes (B) wrong.
- In block (burst) transfer the DMA holds the bus and sends a whole block in one go. This gives the highest I/O bandwidth.
Interrupt handling: with polling the CPU has to check the devices one by one to find which one needs service, which is slow. With vectored interrupts the device supplies the address of its own service routine, so service starts at once. This makes (D) wrong.
Block transfer with vectored interrupts is the best on both counts.
Answer: (C)
DMA mode:
- Transparent DMA uses the bus only when the CPU is not using it. The CPU is never slowed, but the device must wait for free bus time, so the I/O rate is low. This makes (A) wrong.
- In cycle stealing the device moves one word, gives the bus back, and gets it again only after a few CPU cycles. So the I/O rate is limited. This makes (B) wrong.
- In block (burst) transfer the DMA holds the bus and sends a whole block in one go. This gives the highest I/O bandwidth.
Interrupt handling: with polling the CPU has to check the devices one by one to find which one needs service, which is slow. With vectored interrupts the device supplies the address of its own service routine, so service starts at once. This makes (D) wrong.
Block transfer with vectored interrupts is the best on both counts.
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:
Consider the following C-function in which a[n] and b[m] are two sorted integer arrays and c[n+m] be another integer array.
I. jm, k=n+j-1, and a [n-1]b[j] if i=n
II. in, k=m+i-1, and b[m-1]a[i] if j=m
void xyz (int a[],int b[],int c[]){
int i, j, k;
i=j=k=0;
while((i < n) && (j < m))
if (a[i] < b[j]) c[k++]=a[i++];
else c[k++]=b[j++];
} Which of the following condition(s) hold(s) after the termination of the while loop ?I. jm, k=n+j-1, and a [n-1]b[j] if i=n
II. in, k=m+i-1, and b[m-1]a[i] if j=m
Answer: (D)
The loop runs while both and , so it stops when one array is used up: either or .
Each pass copies exactly one element into and does together with one of or . Since all three start at 0, at all times.
Take the case . Then , and statement I says , so I is false. Take the case . Then , and statement II says , so II is false.
Both statements are false, so option (C) is wrong too, because it needs one of them to hold. (If started at and the loop used , then and the statements would change.)
Answer: (D)