search
Log In
43 votes
6.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}$
in CO and Architecture
edited by
6.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?

 

14

@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
0
what are the content of Stack pointer
0

PC will be saved at location from (016F)H
rather than (016E)H.

2 Answers

65 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$


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
11
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
I can't understand the addition.

1B = 32 bits, i.e in (016E) from left 5 bits will change, right??

2 to 5 = 32

(016E) + 11111. It should be like that, right???
1
For addition doubts,

0000 0001 0110 1110
0000 0000 0000 0010
-----------------------------
0000 0001 0111 0000, which is $(0170)_{16}$

Now, when we add 0010 to this again, only the block will undergo changes, especially the last two bits, giving us:

0000 0001 0111 0010, which is $(0172)_{16}$
–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 
     
9
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
0
in question they have mentioned ..stack is starting from (0100) ..and current value is (016E) so it's incrementing while pushing the elements!
Answer:

Related questions

24 votes
3 answers
1
5.4k views
Assume that for a certain processor, a read request takes $50\:\text{nanoseconds}$ on a cache miss and $5\:\text{nanoseconds}$ on a cache hit. Suppose while running a program, it was observed that $80\%$ of the processor's read requests result in a cache hit. The average read access time in nanoseconds is ______.
asked Feb 12, 2015 in CO and Architecture jothee 5.4k views
23 votes
6 answers
2
5.2k views
A processor has $40$ distinct instruction and $24$ general purpose registers. A $32$-bit instruction word has an opcode, two registers operands and an immediate operand. The number of bits available for the immediate operand field is_______.
asked Feb 12, 2016 in CO and Architecture Akash Kanase 5.2k views
37 votes
4 answers
3
4.7k views
In a connected graph, a bridge is an edge whose removal disconnects the graph. Which one of the following statements is true? A tree has no bridges A bridge cannot be part of a simple cycle Every edge of a clique with size $\geq 3$ is a bridge (A clique is any complete subgraph of a graph) A graph with bridges cannot have cycle
asked Feb 13, 2015 in Graph Theory jothee 4.7k views
18 votes
5 answers
4
5k views
Consider the following routing table at an IP router: $\begin{array}{|l|l|l|} \hline \textbf {Network No} & \textbf {Net Mask} & \textbf{Next Hop} \\\hline \text {128.96.170.0} & \text{255.255.254.0} & \text{Interface $0$} \\\hline\text {128.96.168.0} & \text{255.255.254.0} & \text{Interface $ ... i-a, ii-c, iii-e, iv-d i-a, ii-d, iii-b, iv-e i-b, ii-c, iii-d, iv-e i-b, ii-c, iii-e, iv-d
asked Feb 13, 2015 in Computer Networks jothee 5k views
...