in CO and Architecture retagged by
8,815 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)
in CO and Architecture retagged by
8.8k views

1 comment

Question ye batara ki
X++ karna matlab push karna aur ek step size increment karna address ko X-- mtlb pop karna aur ek step size decrement karna address ko
Fir ye puchha ki aisa kaunsa address hai jo ek stack se 2 baar pop karke unko add karke fir push karra

2
2

5 Answers

38 votes
38 votes
Best answer
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

4 Comments

Thanks
0
0

@Cristine

yeah it would do the same.

0
0
Yes @Cristine, it’s like pop X , then pre-decrement X (now, stack pointer goes to second topmost element) then again pop X, then perform ADDITION. So, your operation is also correct.
0
0
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)

2 Comments

how you can be sure that source is evaluated first? the operator doesn't specify that!
0
0
I think because, the decoder see the format of the instruction (opcode, (R1), (R2)), he will first extract the specific bits of opcode as per defined in the architecure, then he will extract the next specific bits of the instruction (that is address).. since the extraction started from extracting opcode that means from left to right.. I don't think he will extract the bits of first field and then last field and then the middle one.. because extracting this way makes no advantage.. so he will follow one convention that is extraction from left to right.. (this is just my educated guess that's whole depend on architecture implementation)... I will choose (A)
5
5
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

2 Comments

NICELY  EXPLAINED
0
0
Here Logic is on Pre and Post increment/Decrement operation. and Two POP operation will be performed if both operand address is different.
how you come to this point ...i think i did not get question
0
0
1 vote
1 vote
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