This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Stack pointer alignment


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]