Skip to content
Related Articles

Related Articles

Improve Article
GATE | Gate IT 2008 | Question 36
  • Last Updated : 19 Nov, 2018

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.
(A) ADD (X)−, (X)
(B) ADD (X), (X)−
(C) ADD −(X), (X)+
(D) ADD −(X), (X)+


Answer: (A)

Explanation:  

Effective address is the address of the operand.
In the given question format is (opcode, source, destination),
destination ← source op destination
Ex- ADD (X),(Y) ->
Source=location X
Destination=location Y
Operand at Y=operand at X +operand at Y

Here,
-X = decrement pointer X and then use the new location pointed by pointer for the operand.
+X = increment pointer X and then use the new location pointed by pointer for the operand.
X- = decrement pointer X but first use the old location pointed by X.
X+ = increment pointer X but first use the old location pointed by X.

PointerMemory locationData
XMemory location 10010
X-1Memory location 995

Then,our output should pop the first two elements , i.e. 10 and 5 and put that result in memory location at 99.

1. ADD (X)- ,(X) ->  Take operand1 as data at memory location X and then decrement X. Operand1 taken as data memory location 100 = 10,



X=X-1;
X=99;

Then take operand 2 as data at memory location new X , Operand2= 5;
Now, push back their addition at location X,which is still 99
So, our result is location 99 is filled with 15 which is the desired result.

2.  ADD (X), (X)−
Take operand1 as data at memory location X.Operand1 taken as data memory location 100 = 10, Then take operand 2 as data at memory location  X which is still 100, Operand 2= 10;
Now, push back their addition at location X,which is 100
So,our result is location 100 is filled with 20 which is not the desired result.

3.  ADD -(X), (X)+
Decrement and then take operand1 as data at memory location X. So X=99; Operand1 taken as data memory location 99 = 5,
Then increment and then take operand 2 as data at memory location X
X=X+1;
X=100;

Operand 2= 10;
Now, push back their addition at location X,which is 100
So,our result is location 100 is filled with 15 which is not the desired result.

4. ADD -(X), (X)
Decrement and then take operand1 as data at memory location X. So X=99;
Operand1 taken as data memory location 99 = 5,
Then take operand 2 as data at memory location X which is 99
Operand 2= 5;
Now, push back their addition at location X,which is 99
So,our result is location 99 is filled with 10 which is not the desired result.

 

This solution is contributed by Shashank Shanker khare .

Quiz of this Question

Attention reader! Don’t stop learning now. Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :