for example, if you use local to define a local variable localvar on the stack, do you know what the actual command is? Generally, it looks like the following:
push EBP
mov ESP, EBP
sub ESP, 4
the stack now has 4 bytes of space, which is your local variable.
next, if you execute mov localvar, 4, what is the actual command? Yes:
mov dword ptr [ebp-4], 4
so the "Address" of this local variable is the ebp-4 -- obviously, it is not a fixed address. Now you need to pass its "Address" as a parameter to a function. You can write it as follows:
invoke/call somefunc, ADDR localvar
the actually generated command is:
Lea eax, [ebp-4]
push eax
call somefunc
Of course, you can also write:
mov eax, EBP
sub eax, 4
push eax
call somefunc
As you can see, here is an additional command. This is the benefit of Lea. As a result, Lea has another wonderful use: for simple arithmetic computing, especially with 32-bit instructions, it is even more powerful ":
For example, if you want to calculate eax * 4 + EBX + 3 and put the result into edX, what should you do?
MoV edX, eax
SHL edX, 2
Add edX, EBX
Add edX, 3
Now we can use the lea command to solve the problem:
Lea edX, [EBX + eax * 4 + 3]
Lea is interpreted as follows:Load Balancing tive address. (add a valid address to start confusing what is the valid address ??? What is the difference between a valid address and mov ax, [address? In fact, they are all equivalent. Later I learned that an offset can be an immediate number or a result of four arithmetic operations, saving space and improving efficiency)