1

Is there a way to pop the address of the top of the stack and not the content? I want the address into a register and use it to manipulate program later.

Maxsteel
  • 1,922
  • 4
  • 30
  • 55

1 Answers1

3

In AT&T syntax:

leaq (%rsp), %rax

In Intel syntax:

leaq rax, [rsp]

or whatever register you need to use. rax is provided only as an example. The lea command loads the address specified into the register, not the content. For more information, see What's the purpose of the LEA instruction?

You also could do this with a simple mov:

mov %rsp, %rax

or

mov rax, rsp

If you need to actually modify the stack pointer, you can simply add the number of bytes necessary to it.

Community
  • 1
  • 1
owacoder
  • 4,815
  • 20
  • 47