Indeed, lea
is an abbreviation for "load effective address" and therefore it was originally intended to perform address calculations.
However: Does it make any difference if the result of the calculation rsi+rdi
is an address or some integer number?
For the CPU it does not make any difference!
For this reason you can use this instruction instead of add
if you do not require flags to be set.
The operation rax=rsi+rdi
can be done using one lea
instruction or using a combination of two instructions: mov
and add
.
Using only one instruction is typically faster and shorter than using two instructions.
And you can even use the instruction (leal (%rsi,%rdi),%rax
) to perform an 8-, 16- or 32-bit addition because by performing the operation rax=rsi+rdi
you implicitly perform the operations eax=esi+edi
, ax=si+di
and al=sil+dil
.
If I understand your code correctly, a 32-bit addition (eax=esi+edi
) is done by the C code.