This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Stack pointer alignment
- From: "Facundo Ciccioli" <facundofc at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 9 Feb 2007 02:02:10 -0300
- Subject: 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