GATE | GATE-CS-2007 | Question 54
In a simplified computer the instructions are:
Attention reader! Don’t stop learning now. Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.
Learn all GATE CS concepts with Free Live Classes on our youtube channel.
The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block:
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





