The Gateway to Computer Science Excellence

0 votes

The following program uses six different variables p, q, r, s, t and u. The code is:

p=6

q=7

t=p*q

s=t+p

u=8

u=s*p

s=p+u

r=r*q

t=t+p

return t

Assume that all operations take their operands from registers, the minimum number of registers needed to execute this program without spilling are _____________?

Given answer is 5, but my answer is 4.

I think that the step u=8 can be skipped since 'u' is being reinitialized in the next step.

p=6

q=7

t=p*q

s=t+p

u=8

u=s*p

s=p+u

r=r*q

t=t+p

return t

Assume that all operations take their operands from registers, the minimum number of registers needed to execute this program without spilling are _____________?

Given answer is 5, but my answer is 4.

I think that the step u=8 can be skipped since 'u' is being reinitialized in the next step.

+1 vote

Best answer

0

@minal yes u are right. But the system won't know that u=8 is a dead code... It can be seen only by the user. And moreover if system gets it as dead code it would be after entire scan... So 5 registers needed by system.

0

as i know it will check its live or not ... can you give some standard reference for it

as i read in dac https://www.cse.iitm.ac.in/~krishna/cs3300/pm-lecture3.pdf

pls conform once.

check this one also , 7 is correct na given ans 6

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.4k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.2k
- Non GATE 1.4k
- Others 1.4k
- Admissions 595
- Exam Queries 573
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

50,737 questions

57,366 answers

198,496 comments

105,265 users