x86 assembly output

Mike Harrold mharrold@cas.org
Sun Oct 31 23:03:00 GMT 1999


> 
> 
> Does anyone know why the x86 assembly language output from g++ does not
> conform to the standard Intel convention?
> 
> For example, compile the null C++ program, and the output is:
> 
>         .file   "void.cc"
> gcc2_compiled.:
> ___gnu_compiled_cplusplus:
> .text
>         .align 2
> .globl _main
>         .type    _main,@function
> _main:
>         pushl %ebp
>         movl %esp,%ebp
>         call ___main
>         xorl %eax,%eax
>         jmp L1
>         .align 2,0x90
> L1:
>         leave
>         ret
> Lfe1:
>         .size    _main,Lfe1-_main
> 
> 
> 
> The movl line above shows:
> movl %esp,%ebp
> 
> when it should be:
> movl %ebp,%esp
> 
> According to Intel Architecture Software Developer's Manual page 3-286,
> the source register should be on the right, and the destination register
> should be on the left.  However, when the code is compiled, the correct
> form (the latter one) is used.  Borland C++ and MS Visual C++ both follow
> the Intel convention. 
> 
> Is this a bug or does g++ have its own convention?
> 

There's an explanation of this somewhere in the docs if I remember correctly.
However, aside from the Intel convention being backwards, you should consider
that gcc is compiling for the x86 platform, not specifically Intel. You should
also consider consistency, in that all the platforms compile to assembly that
reads source,destination.

/Mike



More information about the Gcc-bugs mailing list