Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the point of LEA EAX, [EAX]?

LEA EAX, [EAX] 

I encountered this instruction in a binary compiled with the Microsoft C compiler. It clearly can't change the value of EAX. Then why is it there?

like image 707
Frederick The Fool Avatar asked Apr 24 '10 05:04

Frederick The Fool


People also ask

What is the purpose of LEA instruction?

The LEA (Load Effective Address) instruction is a way of obtaining the address which arises from any of the Intel processor's memory addressing modes. it moves the contents of the designated memory location into the target register.

What does test EAX EAX do?

eax contains the return value of strcmp. test is like bitwise and except it only sets the flags. Anding a value with itself gives the same value, so test eax, eax sets the flags based on whatever eax contains. ZF is set when the result of an operation is zero.

What is Lea used for in Assembly?

The lea (load effective address) instruction is used to put a memory address into the destination.

What does the LEA instruction write into a register?

The lea instruction places the address specified by its first operand into the register specified by its second operand. Note, the contents of the memory location are not loaded, only the effective address is computed and placed into the register.


1 Answers

It is a NOP.

The following are typcially used as NOP. They all do the same thing but they result in machine code of different length. Depending on the alignment requirement one of them is chosen:

xchg eax, eax         = 90 mov eax, eax          = 89 C0  lea eax, [eax + 0x00] = 8D 40 00  
like image 144
codaddict Avatar answered Oct 04 '22 14:10

codaddict