mov vs lea
We give a simple explanation of why the lea command is used in compliers over mov when performing computation.
2 November 2025
The one sentence summary is function evaluation (dereferencing) commutes with algebra, so don't evaluate (dereference) until the end.
We have two separate units in a standard computation model, the data storage (RAM) and the computation (CPU). Transferring data between these two units is expensive, so it should be minimized. Also, the CPU is stupid, so it can only take in primitive instructions.
Suppose we're interested in evaluating the polynomial
for various values of . Hold off for the moment with identifying as . The stupidity of the CPU requires that all arithmetic operations are binary operations, so write as the composition
where
There are two ways to view the composition expression (2). First, we can view both and as numbers for a given number x. This leads us to using mov, which pulls from memory and feeds it into the computational machine , then pulls again to feed it into the computational machine . Notice that we've retrieved twice.
The alternative, more powerful viewpoint is to view as a symbol as you would in basic algebra. This in turn leads us to interpret and not as numbers but as symbols as well. The power here is that you can perform symbolic simplification, without ever evaluating. This is just enunciating the kneejerk evaluation of simplifying (2) to without ever specifying a value for . Taking this viewpoint, we see that only one retrieval of is necessary. This is the idea behind lea.