Facundo Ciccioli writes: > 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). Something in the library code, probably. I thin the ABI specifies that the stack poiunter will be aligned. But you can't just randomly mess with the stack pointer inside compiler-generated code and expect reasonable results, and if you do trash a hard register, you must tell the compiler you've done so: asm("sub $2, %%esp":::"esp"); Andrew.