Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm not exactly sure what this x86 Add instruction is doing

I'm not exactly sure what this add instruction is doing:

add 0x0(%rbp,%rbx,4),%eax

If it were:

add %rbx,%eax

I know it would add the contents of rbx and the contents in eax and store them back into eax. However, the 0x0(%rbp,%rbx,4) is throwing me off.

like image 340
DomX23 Avatar asked Sep 25 '11 09:09

DomX23


People also ask

How does add work in assembly?

The add instruction adds together its two operands, storing the result in its first operand. Note, whereas both operands may be registers, at most one operand may be a memory location. The inc instruction increments the contents of its operand by one. The dec instruction decrements the contents of its operand by one.

Is INC faster than add?

ADD is not always faster than INC , but it is almost always at least as fast (there are a few corner cases on certain older micro-architectures, but they are exceedingly rare), and sometimes significantly faster.

What is ECX in assembly language?

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 is Lea used for?

The LEA (Load Effective Address) instruction is a way of obtaining the address which arises from any of the Intel processor's memory addressing modes. it moves the contents of the designated memory location into the target register.


1 Answers

That's because it's stupid&confusing AT&T syntax.
In normal Intel syntax it's add eax,dword ptr[rbp+4*rbx+0] ie add the dword at rbp+4*rbx to eax.

like image 147
harold Avatar answered Sep 21 '22 09:09

harold