This question says that the LEA instruction can be used to do arithmetic.
As I understand it, instead of:
inc eax
mov ecx, 5
mul ecx
mov ebx, eax
I can simply write
lea ebx, [(eax + 1) * 5]
The LEA version is only a single instruction as opposed to the 4. However, I don't understand how LEA does the arithmetic without inc
and mul
.
Is the LEA version faster in any way, or does LEA simply run the original instructions in the background?
EDIT: This question is not about the purpose of LEA, but rather how it works internally.