8

I am learning x86 assembly, and have some troubles with the lea instruction.

 0x080486f7 <+21>:  lea    eax,[esp+0x18]

Can anybody explain what happens in this line? In my understanding, it takes the value at [esp+0x18] and interprets the value as an address, and puts the value of what is int the address into eax.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
user1090614
  • 2,575
  • 6
  • 22
  • 27

2 Answers2

15

Basically

mov eax, [esp+0x18]

means

mov eax, esp
add eax, 0x18
mov eax, [eax]

and in C that would look like

eax = *(unsigned int*)(esp + 0x18)

Meanwhile

lea eax, [esp+0x18]

means

mov eax, esp
add eax, 0x18

and in C that would look like

eax = esp + 0x18
higaki
  • 388
  • 3
  • 8
1

It stores esp + 0x18 in eax. In other words, it's just addition. LEA is frequently used to perform basic arithmetic.

StilesCrisis
  • 15,972
  • 4
  • 39
  • 62