Instruction Selection
. straight forward code if efficiency is not an issue
a=b+c |
Mov b, R 0
|
|
d=a+e |
Add c, R 0
|
|
|
Mov R0 , a
|
|
|
Mov a, R0 |
can be eliminated
|
|
Add e, R0 |
|
|
Mov R 0 , d
|
|
|
|
|
a=a+1 |
Mov a, R0 |
Inc a
|
|
Add #1, R 0
|
|
|
Mov R 0, a
|
|
Here is an example of use of instruction selection:
Straight forward code if efficiency is not an issue
a=b+c |
Mov b, R 0
|
|
d=a+e |
Add c, R 0
|
|
|
Mov R0 , a
|
|
|
Mov a, R0 |
can be eliminated
|
|
Add e, R0 |
|
|
Mov R 0 , d
|
|
|
|
|
a=a+1 |
Mov a, R0 |
Inc a
|
|
Add #1, R 0
|
|
|
Mov R 0, a
|
|
Here, "Inc a" takes lesser time as compared to the other set of instructions as others take almost 3 cycles for each instruction but "Inc a" takes only one cycle. Therefore, we should use "Inc a" instruction in place of the other set of instructions.
|