Assume that EA = (X)+ is the effective address equal to the contents of…

2008

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. A.

    ADD (X)−, (X)

  2. B.

    ADD (X), (X)−

  3. C.

    ADD −(X), (X)+

  4. D.

    ADD −(X), (X)+

Attempted by 95 students.

Show answer & explanation

Correct answer: A

Correct instruction: ADD (X)−, (X)

Explanation of why this pops two values, adds them, and pushes the result:

  • Step 1 — Evaluate the source (X)−: the CPU reads the value at address X (the top-of-stack) and then decrements X by one word.

  • Step 2 — Evaluate the destination (X): after the decrement from step 1, X now points to the next stack element (the former second element). The destination refers to that element.

  • Step 3 — Perform the operation: destination ← source + destination. The second element is updated to hold the sum.

  • Step 4 — Final state: X points to the location containing the result. One stack element (the top) was removed and the second element was replaced by the result, which matches pop two, add, push result.

Why the other instructions fail:

  • ADD (X), (X)−: both operands reference the same top element (source reads without changing X, destination reads then decrements). This does not access two distinct top elements.

  • ADD −(X), (X)+: the source pre-decrements before reading (so it does not read the top element), and the destination post-increments after reading; the combination does not correctly access and remove the top two stack values.

  • The duplicate instruction has the same incorrect behavior as the previous point.

Explore the full course: Gate Guidance By Sanchit Sir