-1

So I'm trying to figure out what this function does, but I'm a little puzzled by this instruction sequence:

mov    -0x4(%rsp),%eax
lea    0x0(,%rax,8),%edx

There isn't a mention of rax within the function before that. What would be the value within the rax register--is it just the top of the stack?

The previous line was mov -0x4(%rsp),%eax, so is it just whatever's in eax?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 2
    `eax` is the low 32 bits of `rax` and writing to `eax` clears the top 32 bits. So yeah, `rax` has the 32 bit value from memory at address `rsp-4` zero extended to 64 bits. – Jester Nov 13 '17 at 01:58

1 Answers1

0

"general rule"? No, there can't be a general rule other than tautologies (like "whatever you last put in it, implicitly or explicitly") or very detailed rules that cover everything that implicitly uses rax, like:

  • function return value in most calling conventions
  • low half of a full-multiply result (one-operand mul or imul).
  • quotient after div / idiv
  • low half of the 64b or 128b load result from cmpxchg8b / cmpxchg16b
  • xlatb / lodsb/w/d/q result
  • the abort info after an aborted Transactional Memory operation (RTM)
  • Part of a CPUID result
  • Probably some other implicit EAX/RAX uses that I'm forgetting.

Writing eax always zero-extends into rax (Why do most x64 instructions zero the upper part of a 32 bit register), but writing AL, AH, or AX merge with the old value of RAX.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847