Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 716
Tony The Lion Avatar asked Oct 23 '10 12:10

Tony The Lion


People also ask

What does Leal do in assembly?

leal is the Load Effective Address instruction. The first operand should be a memory location and the second operand should be a register. However, in contrast to movl and addl, leal moves that memory address to the destination register.

What does ECX mean in assembly?

CX is known as the count register, as the ECX, CX registers store the loop count in iterative operations. DX is known as the data register. It is also used in input/output operations. It is also used with AX register along with DX for multiply and divide operations involving large values.

What does Movsbl do in assembly?

Assuming you are talking about x86, the MOVSBL instruction extends a byte (8 bits) representing a signed number to 32-bit signed number. The remaining 24 bits are zeros or ones depending on the sign so that the two's complement value remains.

What does the following instruction do MOV EAX EBX?

mov [eax], [ebx] would mean "move the contents of the memory location pointed to by ebx to the memory location pointed to be eax . That is a memory-to-memory move, which Intel does not support.


2 Answers

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.

like image 184
Nils Pipenbrinck Avatar answered Oct 19 '22 02:10

Nils Pipenbrinck


lea stands for "load effective address"; it is a way to use the sophisticated adressing modes of the IA32 instruction set to do arithmetic. The l suffix is a way to distinguish the size of instruction operands in the syntax of GNU as, that you have on your Linux box.

So, in short, yes, it's a kind of addition instruction. It can also handle multiplications by 2, 4, or 8 at the same time.

See also this related question (where they are using the Intel syntax to discuss the same instruction):

like image 45
Pascal Cuoq Avatar answered Oct 19 '22 02:10

Pascal Cuoq