Stack pointer alignment
Facundo Ciccioli
facundofc@gmail.com
Fri Feb 9 05:50:00 GMT 2007
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
More information about the Gcc-help
mailing list