The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+34 votes
4.3k views

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}$ and it grows upward. The stack pointer (SP) points to the top element of the stack. The current value of SP is $(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}$. After execution of the CALL instruction, the value of the stack pointer is:

  1. $(016A)_{16}$
  2. $(016C)_{16}$
  3. $(0170)_{16}$
  4. $(0172)_{16}$
asked in CO & Architecture by Veteran (116k points)
edited by | 4.3k views
0

what is the significance of this

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

0
  • Load the starting address of the subroutine in PC

what does this do?

 

+5

@Dharmendra Lodhi 

U were asking about the significance of stack, There is the main memory in our computer if we want to take the support of stack  in order to implement recursive calls and nested subroutines then we have only one option in the sense we will have to implement stack in the main memory itself and that part of main memory will act as a stack means it will act same like as stack works like pushing, popping and everything..Along with that stack grows and shrink automatically depending on the need of stack by programs...Here in this question, the stack grows upward...

The stack pointer is used to point the top element of the stack, here the value of SP = (016E)16

Before the fetch of the CALL instruction, value of PC = (5FA0)16

First, we have to load the current value of PC into memory stack, it will take 2 Bytes 

And then we have to push PSW register, stack pointer again incremented by 2, So stack pointer finally incremented by 4

So now the value of SP = (016E)16   +   4   = (0172)16 after execute CALL instruction..

 

+1
great explanation...thank you

2 Answers

+49 votes
Best answer

First we have to consider here memory is byte-addressable 

The CALL instruction is implemented as follows:

  • Store the current value of PC in the stack

    PC is $2$ bytes it means when we store pc in stack it will increase by $2$  
    So current value of SP is $(016E)_{16} +2$
     
  • Store the value of PSW register in the stack
    PSW is $2$ byte it means when we store psw in stack it will increase by $2$  
    So current value of SP is $(016E)_{16}+2+2 =(0172)_{16}$

Correct Answer: $D$

answered by Active (5k points)
edited by
0
how to perform addition in

(016E)16 + 2 + 2

which is hexadecimal number...
+1
@R karthik If u cant do it drctly change both in binary and do.
0
From where is Call Instruction fetched?
only the data is stored in stack? Right?
0
the stack is also a part of memory or you can say the reserved region of main memory which is used to store the PC value, in case if we encounter the instructions like CALL or RETURN we use the stack to store or retrieve the PC value respectively. However, CALL is fetched from memory as all the instructions are fetched.
0
Shouldn't the SP point to the starting byte of the topmost element so that the PC would be able to load it later on? Here the starting byte of PSW content is 0171.
0
If memory were word addressable, will we add 1 each time??
0

@anchitjindal07 yes as 2 bytes have one address allocated then 

0
good explanation anoop sir
+5
016E+1= 016F

016F+1=0170

0170+1=0171

0171+1=0172

 

 

Like that we can do directly in hexadecimal !!
0
Yes preety u can do , memory is byte addressable so for one byte stack pointer will move one place
0
What is the significance of "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"??
–1 vote

Stack in main memory grows upwards. This statement tells that the stack pointer decrements on adding new elements to stack. For more details plz refer to hamacher 2nd chapter. So i think it will work as : 

  • Store the current value of PC in the stack 

    pc is 2 byte it means when we store pc in stack it will deccrease by 2   
    so current value of SP is (016E)16 -2 

     
  • Store the value of PSW register in the stack 
    psw is 2 byte it means when we store psw in stack it will decrease by 2   
    so current value of SP is (016E)16 -2-2 =(016A)16 
     
answered by (393 points)
+8
you saw right sentence but implemented in totally opposit way. generally stack is growing downward that's why we decrement the address of top. but here stack is expanding upward. so we have to add bytes for new top. not minus
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,434 questions
53,630 answers
186,007 comments
70,899 users