1

I am new to x86 assembly and I have a question regarding the movq and leaq instruction. In particular, I would like to know the difference between the following:

1. movq (%rax), %rcx
2. movq %rax, %rcx

3. leaq (%rax), %rcx
4. leaq %rax, %rcx

I am assuming that for 1. the value in the %rax register will be interpreted as a memory access and the value at that memory location will be written into the %rcx register. But what about 2. ? Will the value in the %rax register just directly be written into the %rcx register without accessing memory ? Regarding 3. and 4. I am clueless and not even sure if there is a difference as I know that lea does not access memory and just calculates an address.

jonathansl
  • 49
  • 6
  • 4
    1. Yes, this is 64-bit memory read. 2. Yes, moving a copy of one register's value to another register. 3. Yes, `leaq` won't access memory. Since that memory addressing mode is so simple. this just copies one register to another. `leaq` is much more useful when the addressing mode is more complex, where it will do arithmetic, like addition and scaling. 4. Don't think that is valid assembly/machine code. – Erik Eidt Jan 10 '23 at 18:24
  • LEA is not encodeable with a register source operand, as GAS would tell you if you'd tried to assemble 4. The first lea, 3, is just an inefficient way to do 2, copy a register. – Peter Cordes Jan 11 '23 at 04:12

0 Answers0