Stack pointer alignment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi. I'll save you all the details that I think are irrelevant and go
directly to my question.
I would like to know why the following code doesn't work:

int main() {
   asm("sub $2, %esp");
   printf("Hi, this is a test\n");
   asm("add $2, %esp");

   return 0;
}

By "doesn't work" I mean that the call to printf doesn't have any
effect. Of course if I replace the number 2 (that I substract and the
add to esp) by any multiple of 4, the program does what expected. I
wonder if any of you knows from where does the restriction that the
esp must by a multiple of 4 comes from. From printf? I know that it
doesn't come from the processor (x86).

Thanks in advance,
FaQ

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux