0

Why do we always do

 pushl  %ebp          # save the old base pointer
 movl   %esp, %ebp    # set ebp to the current esp
 movl %ebp, %esp
 popl %ebp

^this, when defining functions in assembly?

Below is my translation of some code without pushes and pops and esp register used to access variables.

asm(
    "_calculateA:;"
    "   movl 8(%esp), %eax;"
    "   andl 4(%esp), %eax;"
    "   ret;"
    );

It is much shorter and works fine, so what's the deal?

  • Let me be precise If a compiler is translating C then okay.... But if I am translating it myself, and let's say a code is indeed really simple, I won't have the need to debug and yet it takes extra lines to write as well as slows down the execution time by microseconds. I wonder whether it would be okay to omit these... – Irakli Koberidze Apr 14 '17 at 14:36
  • Like would it be okay to omit these conventional lines if I'm writing a code as simple as the sum of two numbers? – Irakli Koberidze Apr 14 '17 at 14:39
  • Yes, that's it thanks! – Irakli Koberidze Apr 14 '17 at 15:01

0 Answers0