What is the 0x10 in the "leal 0x10(%ebx), %eax" x86 assembly instruction?

Tony The Lion picture Tony The Lion · Oct 23, 2010 · Viewed 44k times · Source

What the function is of the 0x10 in regards to this LEAL instruction? Is it a multiply or addition or is something else?

leal 0x10(%ebx), %eax

Can someone please clarify? This is x86 assembler on a Linux box.

Answer

Nils Pipenbrinck picture Nils Pipenbrinck · Oct 23, 2010

leal, or lea full name is "Load effective address" and it does exactly this: It does an address calculation.

In your example the address calculation is very simple, because it just adds a offset to ebx and stores the result in eax:

eax = ebx + 0x10

lea can do a lot more. It can add registers, multiply registers with the constants 2, 4 and 8 for address calculations of words, integers and doubles. It can also add an offset.

Note that lea is special in the way that it will never modify the flags, even if you use it as a simple addition like in the example above. Compilers sometimes exploit this feature and replace an addition by a lea to help the scheduler. It's not uncommon to see lea instructions doing simple arithmetic in compiled code for that reason.