Question

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 (0100)16(0100)_{16} and it grows upward. The stack pointer (SP) points to the top element of the stack. The current value of SP is (016E)16(016\text{E})_{16}. 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 (5FA0)16(5\text{FA}0)_{16}. After execution of the CALL instruction, the value of the stack pointer is

Choose one option
Official answer and solution
Official answer
D
From
Official GATE 2015 answer key

Solution

Track stack pointer adjustments as registers are pushed onto the upward-growing stack.

Key architecture details:

  • Memory is byte-addressable.
  • Register size = 2 bytes for both PC and PSW.
  • The stack grows upward (toward increasing memory addresses).
  • Initial SP=(016E)16\text{SP} = (016\text{E})_{16}, pointing to the current top element.

Executing the CALL instruction sequence:

  1. 'Store the current value of PC in the stack':
    Since the stack grows upward and SP points to the top element, SP is incremented by 2 bytes (size of PC):
    SP=(016E)16+2=(0170)16.\text{SP} = (016\text{E})_{16} + 2 = (0170)_{16}.
    PC is stored at this address.
  1. 'Store the value of PSW register in the stack':
    SP is again incremented by 2 bytes (size of PSW):
    SP=(0170)16+2=(0172)16.\text{SP} = (0170)_{16} + 2 = (0172)_{16}.
    PSW is stored at this address.
  1. 'Load the starting address of the subroutine in PC':
    This updates the PC register and does not alter the stack pointer.

Thus, after execution of the CALL instruction, SP=(0172)16\text{SP} = (0172)_{16} (option D).

Final answer

D

Common trap

Subtracting 4 bytes from SP as in downward-growing stacks (such as x86), which would give (016A)16(016\text{A})_{16}.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2015 Computer Science and Information Technology (CS) Session 2
Question
52 of 65, printed as CS Q.42
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.