Question:medium

Consider a processor P whose instruction set architecture is the load-store architecture. The instruction format is such that the first operand of any instruction is the destination operand.
Which one of the following sequences of instructions corresponds to the high-level language statement \(Z = X + Y\)?
Note: X, Y, and Z are memory operands. R0, R1, and R2 are registers.

Show Hint

In a load-store architecture only LOAD and STORE may touch memory, so X and Y must first be loaded into registers, added register-to-register, and the result stored back to Z.
Updated On: Jul 22, 2026
  • ADD Z, X, Y
  • LOAD R0, X
    ADD Z, R0, Y
  • ADD R0, X, Y
    STORE Z, R0
  • LOAD R0, X
    LOAD R1, Y
    ADD R2, R0, R1
    STORE Z, R2
Show Solution

The Correct Option is D

Solution and Explanation

Step 1: A quick way to check load-store legality is to scan every instruction in a candidate sequence and ask two questions, does this instruction access memory, and if it does, is it a LOAD or a STORE. If any non-LOAD/STORE instruction touches memory, the sequence is illegal.

Step 2: Apply this scan to option (A), the only instruction is ADD Z, X, Y. It touches memory through Z, X, and Y while not being a LOAD or STORE. Fails the test.

Step 3: Apply it to option (B), LOAD R0, X passes since it is a LOAD, but ADD Z, R0, Y touches memory through Z and Y while being an ADD. Fails.

Step 4: Apply it to option (C), ADD R0, X, Y touches memory through X and Y while being an ADD. Fails, even though the following STORE Z, R0 is fine on its own.

Step 5: Apply it to option (D), LOAD R0, X and LOAD R1, Y both pass since they are LOADs. ADD R2, R0, R1 touches only registers, so the memory-access rule does not even apply to it, it passes trivially. STORE Z, R2 passes since it is a STORE. All four instructions pass the scan.

Step 6: Since (D) is the only sequence where every instruction touching memory is a LOAD or a STORE, and the register-only ADD correctly computes R0 + R1 = X + Y into R2 before it is stored back to Z, (D) is the unique valid and correct sequence.

\[ \boxed{\text{Option D}} \]
Was this answer helpful?
0

Questions Asked in GATE CS exam