A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

Why does my assembly have the line "mov $0x0, %eax" when optimization is off, and "xor %eax, %eax" when optimization is on? Also, what does "push %ebp\nmov %esp, %ebp" do?

  • This Question is Closed
  1. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    whats %eax?

  2. mathmate
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    I suppose it's because xor %eax %eax puts a zero in %eax a few cycles faster than a mov.

  3. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    push ebp would put ebp to the stack. Mov esp ebp copies ebp to esp.

  4. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The xor can be faster because it won't use a constant as source. Today they'll likely be equally fast on most CPUs, but the xor can produce smaller code (the 0 for the mov has to be stored in the binary, afterall). There are however cases where the xor can be slower - it can introduce a register dependency that may lead to the xor instruction stalling - If another instruction used the register in question as destination before, the xor may stall until that prior result is written to the register and can be used for the xor instruction. The optimizer should be able to figure this one out on a case by case basis - my guess is that you'll see mov and xor used both in different places of compiled code (I'm assuming this is C compilate?), depending on the circumstances.

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.