# GATE | Gate IT 2008 | Question 36

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.

Explanation:

In the given question format is (opcode, source, destination),
destination ← source op destination
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.

Pointer Memory location Data
X Memory location 100 10
X-1 Memory location 99 5

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.

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.

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.

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

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.