retagged by
8,837 views
38 votes
38 votes

Assume that EA = (X)+ is the effective address equal to the contents of location X, with X incremented by one word length after the effective address is calculated; EA = −(X) is the effective address equal to the contents of location X, with X decremented by one word length before the effective address is calculated; EA = (X)− is the effective address equal to the contents of location X, with X decremented by one word length after the effective address is calculated. The format of the instruction is (opcode, source, destination), which means (destination ← source op destination). Using X as a stack pointer, which of the following instructions can pop the top two elements from the stack, perform the addition operation and push the result back to the stack.

  1. ADD (X)−, (X)
  2. ADD (X), (X)−
  3. ADD −(X), (X)+
  4. ADD −(X), (X)
retagged by

5 Answers

Best answer
38 votes
38 votes
It should be A as $998\leftarrow 1000+998.$ $($I am writing only memory locations for sake of brevity$)$
Lets say SP is $1000$ initially then after it calculates the EA of source (which is $1000$ as it decrements after the EA) the destination becomes $998$ and that is where we want to store the result as stack is decrementing.

In case of C and D it becomes $998\leftarrow 998+998.$
edited by
10 votes
10 votes
Answer is A  :-    We can also write this statement like that
for option
X         =  ( X - -)  + X

----------------------------> execution.
X         = top  + X    ( decrement the pointer )

X          = top  + top -1

(top-1) =  top      + ( top -1)
9 votes
9 votes
Ans (a).

Here Logic is on Pre and Post increment/Decrement operation. and Two POP operation will be performed if both operand address is different.

Let X=3

(a). (X)- , (X)

      3 , 2     (Here its decrement will be done after EA Calculation)

(b). (X) , (X)-

     3 , 3  (decrement will be after EA, so in second operand also same address will be used).

(c). -(X) , (X)+

      2, 2 (Pre Decrement will be done and post increment will change X after EA , so same first operand address will be used for second operand).

(d). -(X) , (X)

      2, 2

Clearly for Option (a) two POP operation will be performed where as in other option only one POP is required.
edited by
1 votes
1 votes
Option A and D are both right depending upon how th stack grows and which operand is evaluated first.

Source is fetched first followed by destination operand (and the stack grows to higher addresses): A

Destination operand is fetched first followed by source operand, then destination is evaluated (and the stack grows to higher addresses): D
Answer:

Related questions

21 votes
21 votes
4 answers
1
42 votes
42 votes
4 answers
3