Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the LEAL assembly instruction do?

Tags:

c

x86

assembly

I am a little bit confused about the difference between

leal -4(%ebp), %eax        

and

movl -4(%ebp), %eax 

Can someone explain this to me?

like image 779
Serguei Fedorov Avatar asked Jun 26 '12 17:06

Serguei Fedorov


1 Answers

LEA (load effective address) just computes the address of the operand, it does not actually dereference it. Most of the time, it's just doing a calculation like a combined multiply-and-add for, say, array indexing.

In this case, it's doing a simple numeric subtraction: leal -4(%ebp), %eax just assigns to the %eax register the value of %ebp - 4. It's equivalent to a single sub instruction, except a sub requires the destination to be the same as one of the sources.

The movl instruction, in contrast, accesses the memory location at %ebp - 4 and stores that value into %eax.

like image 173
Adam Rosenfield Avatar answered Sep 20 '22 21:09

Adam Rosenfield