I am not sure if this is an duplicate, but I couldn’t find any answer I want in the similar posts, so feel free to write the link down and close this question if there is an answer.
I am currently studying x86-64 assembly language. From my knowledge, LEA is intended to be used to compute the some arithmetic of the address, and then copy the address into the destination. There is also a lot of case where LEA is just used to compute some arithmetic of some values. Assume x is stored in register %rdi:
long m12(long x){ return x*12; }
Assembly code:
leaq (%rdi,%rdi,2), %rax
salq $2, %rax
Here the return value from the leaq
would be 3*x.
However I have also seen something similar using mov:
movl (%rdx,%rcx,4), %eax
What is the difference between these two?