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 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
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 , pointing to the current top element.
Executing the CALL instruction sequence:
- '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):PC is stored at this address.
- 'Store the value of PSW register in the stack':
SP is again incremented by 2 bytes (size of PSW):PSW is stored at this address.
- '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, (option D).
D
Subtracting 4 bytes from SP as in downward-growing stacks (such as x86), which would give .
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.