Skip to content
Related Articles

Related Articles

GATE | GATE-CS-2007 | Question 54

Improve Article
Save Article
  • Last Updated : 28 Jun, 2021
Improve Article
Save Article

In a simplified computer the instructions are:

GATECS2007Q54

The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block:

GATECS2007Q541

Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?
(A) 2
(B) 3
(C) 5
(D) 6


Answer: (B)

Explanation:
For Instructions of t2 and t3
1. MOV c, t2
2. OP d, t2(OP=ADD)
3. OP e, t2(OP=SUB)

For Instructions of t1 and t4
4. MOV a, t1
5. OP b, t1(OP=ADD)
6. OP t1, t2(OP=SUB)

7. MOV t2, a(AS END Value has To be in the MEMORY)

Step 6 should have been enough, if the question hadn’t asked for final value in memory and rather be in register. The final step require another MOV, thus a total of 3.

Quiz of this Question

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!