Gate 2007, Q54

Lexical analysis, Parsing, Syntax directed translation, Runtime environments, Intermediate and target code generation, Basics of code optimization.

Gate 2007, Q54

Postby VijayentK » Sat Jan 26, 2013 3:51 am

In a simplified computer the instructions are:
OP Rj , R - Performs Rj OP Ri and stores the result in register Ri
OP m, Ri - Performs val OP Ri and stores the result in Ri ,val denotes the content of memory location m.
MOV, m Ri - Moves the content of memory location m to register Ri
MOV , Ri m - Moves the content of register Ri to memory location m.
The computer has only to registers, and OP is either ADD or SUB. Consider the
following basic block:

t1 = a + b
t2 = c + d
t3 = e - t
t4 = t1 - t3
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
--- Carpe Diem ---
VijayentK
Gatementor Regular
Gatementor Regular
 
Posts: 282
Joined: Mon Oct 15, 2012 12:51 pm
My College/Company:: REC, Uttarakhand
Roll Number: 0
Packages: Test Series (TS)

Re: Gate 2007, Q54

Postby VijayentK » Sat Jan 26, 2013 3:52 am

i am getting 3

plz confirm
--- Carpe Diem ---
VijayentK
Gatementor Regular
Gatementor Regular
 
Posts: 282
Joined: Mon Oct 15, 2012 12:51 pm
My College/Company:: REC, Uttarakhand
Roll Number: 0
Packages: Test Series (TS)

Re: Gate 2007, Q54

Postby Unnikuttan » Thu Sep 26, 2013 2:10 pm

I'm getting 3....is it correct.

Unni
Unnikuttan
Gatementor Senior Member
Gatementor Senior Member
 
Posts: 498
Joined: Fri Jun 28, 2013 4:34 pm
My College/Company:: CUSAT
Roll Number: 9999999

Re: Gate 2007, Q54

Postby yogeuikey » Wed Jan 28, 2015 10:40 pm

MOV a, R1 (1)
OP b, R1 //t1=a+b
MOV R1, t1 (2)//save addition in memory
MOV c, R1 (3)
OP d, R1 //t2=c+d
OP e, R1 // t3=e-t2
OP t1, R1 // t4=t1-t3
MOV R1, t4 (4)

if optimization is applied then t4=a+b+c+d-e
and it can be done in 2 Move operations

So, the answer should be 2 or 4
yogeuikey
 
Posts: 2
Joined: Wed Jan 28, 2015 10:37 pm
My College/Company:: JEC
Roll Number: 12345678

Re: Gate 2007, Q54

Postby Unnikuttan » Wed Feb 04, 2015 12:46 pm

The system has 2 registers available

MOV a,R1
OP b, R1 >>>>t1=a+b
MOV c,R2
OP d, R2 >>>>t2=c+d
OP e,R2 >>>>t3=e-t2
OP R1,R2 >>>t1-t3
MOV R2, t1 >>> The final result should be in memory, hence moved to a variable.


Total MOV operations performed = 3

Please verify.

Unni.
Unnikuttan
Gatementor Senior Member
Gatementor Senior Member
 
Posts: 498
Joined: Fri Jun 28, 2013 4:34 pm
My College/Company:: CUSAT
Roll Number: 9999999


Return to Compiler Design

Who is online

Users browsing this forum: No registered users and 5 guests