1
movl $0,-4(%rsp)  #t=0
leap -4(%rsp),%rax  #&t

I am confused with the meaning of -4(%rsp). In the first line, it seems to represent the memory, but in the second line it seems to be the address. In my opinion, the first line should be movl $0,(-4(%rsp)) Where am I wrong?

dubugger
  • 89
  • 6
  • 1
    `lea` is load effective address. That's why you get the address. The at&t format is `displacement(base,index,scale)` you do not need extra parentheses. – Jester Aug 23 '21 at 12:25
  • Yes, so `-4(%rsp)` represents address, but to move 0 to the this address' location, we need to use `(-4(%rsp))` to represent that I am visiting this address's memory not the number of this address. – dubugger Aug 23 '21 at 12:37
  • 2
    No, you don't need to add extra parentheses. `mov` knows to dereference the address. – Jester Aug 23 '21 at 12:53
  • 1
    The point is that the `lea` instruction is very special. In all other instructions, `-4(%rsp)` does a load from memory and uses the loaded value as the operand (if a source), or takes the result of the computation and stores it to memory (if a destination). But `lea` skips the load and instead uses the address itself as the operand. – Nate Eldredge Aug 23 '21 at 13:37
  • Take the addressing modes in the context of the whole instruction, which informs whether an operand is a source vs. target, and whether a memory operation is involved or merely the address computation. – Erik Eidt Aug 23 '21 at 15:59
  • Parentheses around a register indicate a memory operand accessing memory. `lea` is the one exception. – fuz Aug 23 '21 at 23:46

0 Answers0