This is the mail archive of the gcc-bugs@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]

Re: Optimization bug on i386, stack fiddling


> 
> 	int printf(const char *, ...);
> 	int main() 
> 	{
> 	    asm ("pushl %ebp");
> 	    printf("Hello world\n");
> 	    asm ("popl %ebp");
> 	    return 0;
> 	}

I'm sorry, but you can't do that.  asm statements may not modify the
stack pointer (or the frame pointer, PIC register, or anything else
that is "special").

> 
> 	    asm ("pushl %edi");
> 	    asm ("pushl %esi");
> 	    asm ("pushl %eax");
> 	    asm ("pushl %ebx");
> 	    asm ("pushl %ecx");
> 	    asm ("pushl %edx");
> 	    foo();
> 	    asm ("popl %edx");
> 	    asm ("popl %ecx");
> 	    asm ("popl %ebx");
> 	    asm ("popl %eax");
> 	    asm ("popl %esi");    
> 	    asm ("popl %edi");

Try
asm ("all the pushes
      call foo
      all the pops");

or, even better, leave the saving of registers to the compiler:

asm ("call foo" : : : "eax", "ebx", "ecx", ...);

Note that you can't use %ebp the same way.

Bernd


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]