1

In the following assembly:

movq $22,       -8(%rbp)
movq -8(%rbp),  %rdx

# How to memory the *memory_address* of -8(%rbp) into %r11 ?
# For the sake of this example, let's assume: rbp - 8 = 0x00007fffffffe410
movq -8(%rbp),  %r11

How would I run the third instruction properly? After running it the register value should be:

  • rdx: 0x16
  • r11: 0x00007fffffffe410

In other words, how to copy the memory address over into a register rather than the value contained at that memory address?

samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58
  • 1
    Does this answer your question? [What's the purpose of the LEA instruction?](https://stackoverflow.com/questions/1658294/whats-the-purpose-of-the-lea-instruction) You aksed it the other way around but that probably still helps – harold Aug 22 '20 at 20:56
  • @harold thanks, what then would be the correct syntax of the last instruction with the suffixes and all? Would it be `leaq -8(%rbp), %r11` or would I need square brackets? – samuelbrody1249 Aug 22 '20 at 20:59
  • 1
    The square brackets and the opposite operand order are features of the Intel syntax, but you're using AT&T syntax so you would use exactly the same syntax as you used for `movq` but with `leaq` instead – harold Aug 22 '20 at 21:01
  • 3
    @harold I see. So more or less, `mov` moves the value at an address, and `lea` moves the address itself to the destination? – samuelbrody1249 Aug 22 '20 at 21:03
  • @harold: found a good duplicate with AT&T examples, turns out I wrote an answer on [x86-64 instruction set, AT&T syntax, confusion regarding lea and brackets](https://stackoverflow.com/q/61304524) with some C `char * p = &array[idx]` type examples and their AT&T `lea` equivalent. Found with google for `site:stackoverflow.com att lea` – Peter Cordes Aug 22 '20 at 21:31
  • @samuelbrody1249: Also related, re: static addresses: normally use RIP-relative LEA [How to load address of function or label into register in GNU Assembler](https://stackoverflow.com/q/57212012) – Peter Cordes Aug 22 '20 at 21:32

0 Answers0