2
votes

I can't understand this question.

"The content of the top of memory stack is 5320. The content of the stack pointer(SP) is 3560. A two-word call subroutine instruction is located in memory at address 1120 followed by the address field of 6720 at location 1121. What are the contents of PC, SP and the top of the stack :

  • Before the call instruction is fetched from the memory
  • After the call instruction is executed.
  • After the return from subroutine"

1.Before the call instruction is fetched , the PC holds the address of the call instruction in memory that is 1120 . At that time the SP = 3560 and M[SP] = 5320.

2.After the call instruction is decoded and executed , the PC is incremented (PC = PC + 1) , and is equal to 1121 , which is the return address , and is stored on the top of the stack. Suppose , the stack pointer decreases by 1 for each push (SP = SP - 1) , and increases by 1 for each pop (SP = SP + 1). So, The SP value would be 3560 - 1 = 3559 , and M[3559] = 1121 (return address).

3.After the subroutine has finished executing , the return address is transferred to PC (PC = M[SP]) and SP is incremented(pop) (SP = SP + 1) So , now PC = 1121 and SP = 3559 + 1 = 3560 , and the M[SP] = M[3560] = 5320.

By far , this is all I know , as being a beginner.

My question is :

1. Is what I did right ?

2. If not then explain why.

3. If yes then what is the significance of the other values that don't serve any role in computation?

1

1 Answers

0
votes

1) The answer to this subpart is correct.

2) After the execution of call instruction the current value in PC will be pushed onto the stack, since it is a push operation the Stack pointer will be decremented by 1, and the new PC value will be the starting address of the subroutine. PC:6720 Sp=Sp-1; 3560-1=3559 TOS 1122 :This is a bit tricky, in this case we cannot determine where we have to jump, unless we fetch and decode the instruction at 1121 which will tell us where to jump. Since the address(6270) is obtained from 1121 the PC must be pointing to 1122 before its value was pushed onto the stack. Hence 1122 was be pushed onto the stack.

3)TOS will be poped and that will be our new PC. TOS was 1122 so, PC:1122 New TOS will be the value before 1122, which was the initial value: 5320. Pop operation increments the value of SP, SP=SP+1=3560