Inline Temp
- You have a temporary variable that is assigned and used just once or a few times.
Replace all references to that temporary value with the actual expression.
... eax = 0xff; ecx = ecx & eax; edx = eax | edx; ...
⇓
... ecx = ecx & 0xff; edx = 0xff | edx; ...
Motivation
The expression depth of Assembly code is very shallow, as individual Assembly instructions can only perform basic arithmetic operations. This leads to an excessive use of temporary variables, as the compiler breaks down an expression into smaller sub-expressions. These temporary variables should be inlined so that the full expression may be recovered and easily understood.
Also, on many processor architectures a register access is quicker than storing an immediate constant value, or it produces a smaller code footprint, therefore optimizing compilers often allocate registers to hold frequently used constants (including addresses of frequently used functions). But it is no advantage for the code comprehension having temporary variables used as aliases for constants or functions.
Mechanics
- Replace the variable by its expression in the statements the value is used.
- Remove the variable assignment.
- Remove the variable declaration if the variable is no longer used.