Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "lea eax, [ebx + eax]" and "add eax, ebx" in x86-32 assembly?

Tags:

x86

assembly

GCC made me some assembly code, and inside theres this statement:

lea eax, [ebx+eax]

(Intel Syntax) Just curious, what would the difference between that, and:

add eax, ebx

Be?

eax, and ebx contains return values from functions :)

mov eax, DWORD PTR [ebp+8]
mov DWORD PTR [esp], eax 
call CALC1
mov ebx, eax.
mov eax, DWORD PTR [ebp+8]
mov DWORD PTR [esp], eax
call CALC2
lea eax, [ebx+eax]
like image 223
Skeen Avatar asked Nov 30 '22 17:11

Skeen


1 Answers

One difference that immediately springs to mind is that lea doesn't affect the flags, whereas add does.

It is impossible to say without seeing the rest of the assembly code whether this is of any relevance. It could simply be an artefact of the GCC's code generator (i.e. it could in fact be producing code for a more general case or just using lea as a more flexible add.)

like image 132
NPE Avatar answered Dec 05 '22 05:12

NPE