Extract Local Variable
- A register or the stack is used to hold the value of a local variable.
Define a new local variable with the appropriate type, and change all local references to that stack location or register into a reference to that variable.
void loc100() {
...
eax = ...;
...
...
... = eax;
...
}
⇓
void loc100() {
int var1;
...
var1 = ...;
...
...
... = var1;
...
}
Motivation
During compilation, local variables are mapped into registers or stack positions. This transformation must be reversed in order to improve code understanding.
Mechanics
- Declare a new variable in the function scope.
- Replace all references to the specified register or stack position by a reference to the newly created variable.