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 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 statring 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:
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:
- 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).
- Size of Pushed Elements:
- The Program Counter (PC) is of size 2 bytes.
- The Program Status Word (PSW) is of size 2 bytes.
- 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 bytes ( bytes).
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.
