I was trying to understand how Address Computation Instruction works, especially with leaq command. Then I get confused when I see examples using leaq
leaq
LEA is for calculating the address. It doesn't dereference the memory address
It should be much more readable in Intel syntax
m12(long): lea rax, [rdi+rdi*2] sal rax, 2 ret
So the first line is equivalent to rax = rdi*3 Then the left shift is to multiply rax by 4, which results in rdi*3*4 = rdi*12
rax = rdi*3
rdi*3*4 = rdi*12