Consider the same data as above question. What is the minimum number of registers needed in the instruction set architecture of the processor to compile this code segment without any spill to memory? Do not apply any optimization other than optimizing register allocation.
Explanation: Note that for solving the above problem we are not allowed for code motion.
So, we will start analyzing the code line by line and determine how many registers will be required to execute the above code snippet.
Assuming the registers are numbered R1, R2, R3 and R4. The analysis has been shown in the table below
So from the above analysis we can conclude that we will need minimum 4 registers to execute the above code snippet.
This explanation has been contributed by Namita Singh.
Quiz of this Question
- GATE | GATE CS 2012 | Question 19
- GATE | GATE CS 2011 | Question 43
- GATE | GATE CS 2013 | Question 50
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2018 | Question 65
- GATE | GATE CS 2018 | Question 64
- GATE | GATE CS 2018 | Question 63
- GATE | GATE CS 2018 | Question 62
- GATE | GATE CS 2018 | Question 61
- GATE | GATE CS 2018 | Question 60