GATE 2008
185 questions
MCQ 1851-mark 52 · 2-mark 133
Questions 56–60 of 185
Assume that EA = (X)+ is the effective address equal to the contents of location X, with X incremented by one word length after the effective address is calculated; EA = -(X) is the effective address equal to the contents of location X, with X decremented by one word length before the effective address is calculated; EA = (X)- is the effective address equal to the contents of location X, with X decremented by one word length after the effective address is calculated. The format of the instruction is (opcode, source, destination), which means (destination source op destination). Using X as a stack pointer, which of the following instructions can pop the top two elements from the stack, perform the addition operation and push the result back to the stack.
Answer: (A)
The format is ADD source, destination, and it means destination source + destination. Here X is the stack pointer and points to the top element. Take a word as 2 bytes and X = 1000 at the start, so the top is at 1000 and the next element is at 998. Popping uses (X)-, which reads at X and then decreases X, so here the stack grows toward higher addresses.
(A) ADD (X)-, (X): source address is 1000, then X becomes 998. The destination address is 998. So . Both top elements are popped and added, the sum is stored at 998, and X = 998 now points to it as the new top. This is the required operation.
(B) ADD (X), (X)-: both addresses are 1000, so . It adds the top to itself.
(C) ADD -(X), (X)+: X becomes 998 first, so both addresses are 998 and . It adds the second element to itself.
(D) ADD -(X), (X): X becomes 998 first, so again .
Answer: (A)
(A) ADD (X)-, (X): source address is 1000, then X becomes 998. The destination address is 998. So . Both top elements are popped and added, the sum is stored at 998, and X = 998 now points to it as the new top. This is the required operation.
(B) ADD (X), (X)-: both addresses are 1000, so . It adds the top to itself.
(C) ADD -(X), (X)+: X becomes 998 first, so both addresses are 998 and . It adds the second element to itself.
(D) ADD -(X), (X): X becomes 998 first, so again .
Answer: (A)
A processor that has the carry, overflow and sign flag bits as part of its program status word (PSW) performs addition of the following two 2's complement numbers 01001101 and 11101001. After the execution of this addition operation, the status of the carry, overflow and sign flags, respectively will be:
Answer: (B)
Add the two 8-bit numbers.
The 8-bit result is , with a carry out of the msb.
- Carry flag , since there is a carry out of the msb.
- Overflow flag . In 2's complement, overflow occurs only when both operands have sign bit 0 and the result has sign bit 1, or when both have sign bit 1 and the result has sign bit 0. Here the operands have different sign bits (0 and 1), so overflow cannot occur. (Check: , which fits in 8 bits.)
- Sign flag , since the msb of the result is 0.
Answer: (B)
The 8-bit result is , with a carry out of the msb.
- Carry flag , since there is a carry out of the msb.
- Overflow flag . In 2's complement, overflow occurs only when both operands have sign bit 0 and the result has sign bit 1, or when both have sign bit 1 and the result has sign bit 0. Here the operands have different sign bits (0 and 1), so overflow cannot occur. (Check: , which fits in 8 bits.)
- Sign flag , since the msb of the result is 0.
Answer: (B)
In an instruction execution pipeline, the earliest that the data TLB (Translation Lookaside Buffer) can be accessed is
Answer: (C)
The data TLB translates a virtual address into a physical address, so it needs the virtual address as its input.
The effective address is the address that results from applying the addressing mode (indexed, base plus offset and so on). It is still a virtual address, and the CPU forms it fully only when the effective address calculation is complete. The physical address comes only from the TLB or the page table.
So the TLB lookup cannot start before or during the effective address calculation (options A and B), because the virtual address is not ready. The earliest it can start is right after that calculation completes. Option (D) is later than necessary: in the usual design the TLB lookup happens before, or alongside, the data cache lookup, since the cache needs the physical address.
Answer: (C)
The effective address is the address that results from applying the addressing mode (indexed, base plus offset and so on). It is still a virtual address, and the CPU forms it fully only when the effective address calculation is complete. The physical address comes only from the TLB or the page table.
So the TLB lookup cannot start before or during the effective address calculation (options A and B), because the virtual address is not ready. The earliest it can start is right after that calculation completes. Option (D) is later than necessary: in the usual design the TLB lookup happens before, or alongside, the data cache lookup, since the cache needs the physical address.
Answer: (C)
Which of the following must be true for the RFE (Return From Exception) instruction on a general purpose processor?
I. It must be a trap instruction
II. It must be a privileged instruction
III. An exception cannot be allowed to occur during execution of an RFE instruction
I. It must be a trap instruction
II. It must be a privileged instruction
III. An exception cannot be allowed to occur during execution of an RFE instruction
Answer: (D)
I. Trap instruction: true. RFE changes the processor mode (kernel to user) and reloads the PC and status from the saved values in one indivisible step. This mode change plus jump is how a trap instruction works.
II. Privileged: true. RFE can switch the processor out of kernel mode. If user programs could run it, they could give themselves kernel rights. So only the kernel may execute it.
III. No exception during RFE: true. RFE is restoring the saved PC and status. If another exception came in the middle, this half-restored state would be lost or overwritten, and the return address could not be recovered. So exceptions must not occur during RFE.
All three hold.
Answer: (D)
II. Privileged: true. RFE can switch the processor out of kernel mode. If user programs could run it, they could give themselves kernel rights. So only the kernel may execute it.
III. No exception during RFE: true. RFE is restoring the saved PC and status. If another exception came in the middle, this half-restored state would be lost or overwritten, and the return address could not be recovered. So exceptions must not occur during RFE.
All three hold.
Answer: (D)
Which of the following is/are true of the auto-increment addressing mode?
I. It is useful in creating self-relocating code
II. If it is included in an Instruction Set Architecture, then an additional ALU is required for effective address calculation
III. The amount of increment depends on the size of the data item accessed
I. It is useful in creating self-relocating code
II. If it is included in an Instruction Set Architecture, then an additional ALU is required for effective address calculation
III. The amount of increment depends on the size of the data item accessed
Answer: (C)
In auto-increment mode, the register holds the address of the operand. The operand is fetched and then the register is increased.
I is false. Self-relocating code can be loaded at any address, and it works from a base address. Auto-increment only steps through data such as an array, so it does not help here.
II is false. The effective address is simply the register contents, and the increment can be done by the same ALU after the fetch. An extra ALU may speed up a pipeline, but it is not required.
III is true. After the access, the register must point to the next data item. So it is increased by the size of the item: 1 for a byte, 2 for a 16-bit word, 4 for a 32-bit word.
Only III is true.
Answer: (C)
I is false. Self-relocating code can be loaded at any address, and it works from a base address. Auto-increment only steps through data such as an array, so it does not help here.
II is false. The effective address is simply the register contents, and the increment can be done by the same ALU after the fetch. An extra ALU may speed up a pipeline, but it is not required.
III is true. After the access, the register must point to the next data item. So it is increased by the size of the item: 1 for a byte, 2 for a 16-bit word, 4 for a 32-bit word.
Only III is true.
Answer: (C)