Given a byte addressable system.Say the word size(= register size) is 2 bytes.The stack grows upwards and currently the stack pointer is at 0x016E.The CALL instruction is of two words,the opcode word and the other is the starting address of the subroutine.The CALL instruction works as follows :
i)load the PC,PSW onto the stack;
ii)load the starting address of the subroutine in PC.
PC contents before CALL instruction is 0x5FA0(filler info I'm assuming).What is the value of the stack pointer after the execution of the CALL instruction ?
The answer is 0x172.
So this is what I can't wrap my head around. PC + PSW + CALL = 8 bytes on stack.Or is the CALL instruction not stored on stack ? A clear sequence of events would be much appreciated.Thanks in advance!
According to the listed rules you gave this should happend
Before the call
...
0x16a uuuu PC 0x5fa0
0x16c uuuu
0x16e uuuu <-- Stack pointer uuuu = Undefined but allocated
0x170 xxxx xxxx = Undefined and not allocated
0x172 xxxx
0x174 xxxx
...
After the call
...
0x16a uuuu PC 0x????
0x16c uuuu
0x16e uuuu uuuu = Undefined but allocated
0x170 5fa4 (Return address) xxxx = Undefined and not allocated
0x172 PSW <-- Stack pointer
0x174 xxxx
...
I've drown the stack with increasing address toward the bottom as I'm used with down growing stack but the stack is actually growing up.
The return address pushed on the stack is 0x5fa4
because the routine must return after the call and at 0x5fa0-0x5fa1
there is the call opcode and at 0x5fa2-0x5fa3
there is the call operand.
Suppose that the call instruction is this
call 0x1234
And that the opcode for the absolute 1 call
instruction is 0xfffe
. The memory at 0x5fa0
would be
...
0x5f9c ????
0x5f9e ????
0x5fa0 0xfffe <-- Call opcode
0x5fa2 0x1234 <-- Call operand
0x5fa4 ????
0x5fa6 ????
...
1 Ignore this adjective, just make the example easier.
The push operation is actually two operations:
This is why I drown the stack in words.
This kind of stack is called Full Ascending, as the stack pointer grown towards higher addresses and point to the last word stored.
I inferred this kind of stack by the answer you gave, it is not the only one, see this case for the ARM stack (no assembly instructions involved).
The call push the PC , a word, on the stack, being the stack pointer 0x16e
it is incremented by two giving 0x170
and the PC is stored there at 0x170-0x171
. Same thing for the the PSW (which I assume is a Program Status Word ) which is stored at 0x172-0x173
with the stack pointer pointing at 0x172
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.