Open In App

GATE | GATE-CS-2004 | Question 10

Like Article
Like
Save
Share
Report

Consider the grammar rule E → E1 – E2 for arith­metic expressions. The code generated is targeted to a CPU having a single user register. The sub­traction operation requires the first operand to be in the register. If E1 and E2 do not have any com­mon sub expression, in order to get the shortest possible code

(A)

E1 should be evaluated first

(B)

E2 should be evaluated first

(C)

Evaluation of E1 and E2 should necessarily be interleaved

(D)

Order of evaluation of E1 and E2 is of no consequence


Answer: (B)

Explanation:

  E -> E1 – E2 Given that E1 and E2 don\’t share any sub expression, most optimized usage of single user register for evaluation of this production rule would come only when E2 is evaluated before E1. This is because when we will have E1  evaluated in the register, E2 would have been already computed and stored at some memory location. Hence we could just use subtraction operation to take the user register as first operand, i.e. E1 and E2 value from its   memory location referenced using some index register or some other form according to the instruction. Hence correct answer should be (B) E2 should be evaluated first. 


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads