x86 stack-frame to stack-frame move

From: Frode Vatvedt Fjeld (frodef_at_cs.uit.no)
Date: 02/19/04


Date: Thu, 19 Feb 2004 18:54:41 +0000 (UTC)


[I posted this first in comp.arch, and someone suggested I might ask
this question here on comp.lang.asm.x86.]

>>From a (recent) x86 compiler perspective, what's the best way to copy
one stack-frame location to another? For example, to copy location
(ebp -8) to (ebp -12):

  mov eax (ebp -8)
  mov (ebp -12) eax

Now, assuming you don't need the contents of (ebp -8) for anything
else, will this be equally effective?

  push (ebp -8)
  pop (ebp -12)

In the first example, assuming again that the following instructions
will break any dependencies on eax, I believe the CPU will assign eax
to some virtual scratch register. The question is, will this also
happen with the second example? If the two versions are equally
efficient, the second is preferrable since it frees up eax (or some
other gp register) for other use.

So I suppose my question is this: can I expect recent x86 instruction
decoders to recognize such a push+pop sequence as something equally
efficient to the explicit register version?

Btw: One of my hard-copy P4 manuals mentions on the reference page for
the push instruction that a back-to-back push/pop pair that references
memory (rather than a register) will not require the extra cycle that
memory referencing push/pop normally consume. This suggests to me that
the instruction decoder does indeed special case such push/pop pairs,
but it's still a bit vague.

Thanks,

-- 
Frode Vatvedt Fjeld


Relevant Pages

  • VMI Interface Proposal Documentation for I386, Part 5
    ... to three register arguments. ... of the native instruction set. ... Most of these calls behave as standard C functions, and as such, may ... clobber registers EAX, EDX, ECX, flags. ...
    (Linux-Kernel)
  • Re: Bit extraction
    ... The register EAX has its low 16 bits being AX, ... I think the NOP goes in place to allow it to pair with the instruction ... V pipeline on the superscalar Pentium Pro+, ...
    (comp.lang.asm.x86)
  • Re: An Object-Oriented Syntax for x86 Assembly
    ... Ok, this is probably better, or easier, then thrashing a register. ... > second operand that specifies the size. ... I'd expect that one to read from EAX only, ... > which would be exactly the same instruction as above, ...
    (alt.lang.asm)
  • MOVZX has stall register
    ... It is very interesting that I want to mention why MOVZX would have ... EAX, EAX. ... It makes the processor into thinking that this register is truly ... 32 bits register plus it has to use AND instruction to mask only 8 ...
    (comp.lang.asm.x86)
  • Re: increment values from stdin
    ... If the result of the previous operation was zero, the zero-flag bit is set to one. ... Note that "previous operation" means the last operation that affects the flags - not necessarily the immediately preceeding instruction. ... I wrote "test eax, eax". ...
    (comp.lang.asm.x86)