Skip to content
Official PYQ · 2015

GATE CS 2015 Set 2 Q42 — Machine Instructions and Addressing Modes

Explain with AI

Consider a processor with byte-addressable memory. Assume that all registers, including program counter (PC) and Program Status Word (PSW), are size of two 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(016E)_{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 statring address of the subroutine in PC

The content of PC just before the fetch of a CALL instruction is (5FA0)16(5FA0)_{16}. After execution of the CALL instruction, the value of the stack pointer is:

Choose one option
View worked solution

Answer: D

To find the final value of the stack pointer (SP) after the execution of the CALL instruction, we analyze how the stack operations affect the SP:

  1. Stack Growth Direction: The problem states that the stack grows upward. This means that pushing data onto the stack increases the value of the stack pointer (SP).
  2. Size of Pushed Elements:
    • The Program Counter (PC) is of size 2 bytes.
    • The Program Status Word (PSW) is of size 2 bytes.
  3. Stack Operations during CALL:
    • First, the PC (2 bytes) is pushed onto the stack. This increases the SP by 2.
    • Next, the PSW (2 bytes) is pushed onto the stack. This increases the SP by another 2.

Regardless of whether the stack pointer uses pre-increment or post-increment, pushing two 2-byte values onto an upward-growing stack will increase the stack pointer by a total of 44 bytes (2+2=42 + 2 = 4 bytes).

Final SP=Initial SP+4\text{Final SP} = \text{Initial SP} + 4

Final SP=(016E)16+(4)16=(0172)16\text{Final SP} = (016E)_{16} + (4)_{16} = (0172)_{16}

Note: The size of the CALL instruction (2 words = 4 bytes) affects the return address stored in the PC, but it has no effect on the final value of the stack pointer itself.

Therefore, the correct option is D.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Machine Instructions and Addressing Modes questions