Using LEA on values that aren't addresses / pointers?

前端 未结 3 1428
南旧
南旧 2020-11-22 07:27

I was trying to understand how Address Computation Instruction works, especially with leaq command. Then I get confused when I see examples using leaq

3条回答
  •  醉话见心
    2020-11-22 07:48

    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

提交回复
热议问题