• retagged by
1,826 views
1 1 vote

Consider the following sequence of instructions intended for execution on a stack machine. Each arithmetic operation pops the second operand, then pops the first operand, operates on them, and then pushes the result back onto the stack.

Push b
Push x
Add
Pop c
Push c
Push y
Add
Push c
Sub
Pop z

Which of the following statements is/are correct?

  1. If push and pop instructions each require $5$ bytes of storage, and arithmetic operations each require $1 byte$ of storage, then the instruction sequence as a whole requires a total of $40 bytes$ of storage.
  2. At the end of execution, $z$ contains the same value as y.
  3. At the end of execution, the stack is empty.
    1. I and III only
    2. II and III only
    3. II only
    4. I, II, and III

1 Answer

Best answer
2 2 votes

If push and pop instructions each require 5 bytes of storage , is given in the question, there are in total 7 push and pops operations, so total cost 7*5= 35 Bytes

There are 7 pushes and pops for a cost of 35 bytes, plus 3 arithmetic instructions, for a total of 38 bytes. which contradict option I .

After Instruction Stack Contains New Variables
push  b b  
push x b, x   
add b +  x   
pop  c    c = b + x;
push  c  b + x   c = b + x;
push y b +x , y   c = b + x;
add  b + x + y  c = b + x;
push c 

b + x + y ; b + x 

 c = b + x;
sub y   c = b + x;
pop z    c = b + x; z= y

 

 $$\begin{array}{|c|c|c|} \hline   \textbf{After Instruction} & \textbf{Stack Contains} & \textbf{New Variables}  \\ \hline \text{push b} & b & \\ \hline \text{push x} & b,x &  \\ \hline \text{add} & b+x & \\ \hline \text{pop c} & & c = b +x; \\ \hline \text{push c} & b+x & c = b+x; \\ \hline \text{push y} & b+x,y & c = b+x; \\ \hline \text{add} & b+x+y & c = b+x; \\ \hline \text{push c} & b+x+y\:;b+x & c = b+x; \\ \hline \text{sub} & y & c=b+x; \\ \hline \text{pop z} & & c=b+x\:;z=y \\ \hline \end{array}$$ 

so you can see it clearly from above table that  At the end of execution, z contains the same value as y. which supports option II .

At the end of execution, the stack is empty. it is also true which supports option III

so option II and III is true.

• edited by
Answer:
Position:
Show:

Related questions

3 3 votes
2 answers 2 answers
2.0k
2.0k views
Bikram asked Jan 24, 2017
2,036 views
A $DMA$ module is transferring bytes to memory using cycle stealing mode from a device transmitting at $16 KB/s$. The processor is fetching instructions at the rate of $1...
2 2 votes
2 answers 2 answers
1.4k
1.4k views
Bikram asked Jan 24, 2017
1,385 views
The designers of a computer must select a cache system. They have two options.In first design they uses a direct-mapped cache containing $2$ words per cache line. It woul...
5 5 votes
3 answers 3 answers
1.8k
1.8k views
Bikram asked Jan 24, 2017
1,777 views
Which of the following statements is/are true?Floating point addition is always associative.Shifting a twos-complement integer right by one bit, and filling from the left...
1 1 vote
2 answers 2 answers
1.7k
1.7k views
Bikram asked Jan 24, 2017
1,746 views
A certain computer has a $TLB$ cache, a one-level physically-addressed data cache, $DRAM$, and a disk backing store for virtual memory. The processor loads the instructio...