This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Why is GCC using DI register?
- To: Dan Aalberg <danialaa at conagramalt dot com>
- Subject: Re: Why is GCC using DI register?
- From: Michael Meissner <meissner at cygnus dot com>
- Date: Mon, 14 May 2001 16:20:38 -0400
- Cc: "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
- References: <69C886889C89D411A89C00306E00827455E5C7@VANCOUVER>
On Mon, May 14, 2001 at 12:34:26PM -0700, Dan Aalberg wrote:
> I am trying to get some very simple assembly code from the GCC compiler for
> some testing I am doing.
> For sake of this email, I will over simplify the code.
>
> Here is some simple C code I compile with GCC:
>
> int main(void)
> {
> int a;
> a=5;
> return (a);
> }
>
Ummm, it makes it hard to track what the exact problem is without mentioning,
what is the target system is (I assume from your comments, it is some sort of
386) or the version of the sources. If you built the compiler yourself, please
mention the switches you used to configure the switch with as well.
> when I compile it, I get this for the machine code (with my comments):
>
> push bp
> mov bp,sp ; normal
> sub (w) sp,+08 ;normal
> mov [di-04],0005 ; what the heck is this?
> add [bx+si],al ;where did BX and SI come into play?
> ;what are we adding?
> mov ax,[di-04] ;next 2 lines are stupid.
> mov [di-08],ax
> mov ax,[di-08]
> leave
> retn
>
> what is with BX, DI and SI? I am trying to compile to a flat, non specific
> system and was looking for more of this:
>
> push bp
> mov bp,sp ; normal
> mov [bp-4],0005
> mov ax, [bp-4]
>
> pop bp
> retn
How did you get the above? Did you use the -S or -save-temps switch and look
at the .s file? Or did you use a disassembler? I suspect you used a
disassembler without specifying to target 32-bit instructions (ie, the
instructions you mention use 16-bit register names, etc.). Here for instance
is the code generated a Linux GCC compiler without optimization:
gcc2_compiled:
.text
.align 16
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
movl $5, -4(%ebp)
movl -4(%ebp), %eax
movl %ebp, %esp
popl %ebp
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 3.1 20010315 (experimental)"
Here is the same code compiled with -O2 -fomit-frame-pointer:
gcc2_compiled:
.text
.align 16
.globl main
.type main,@function
main:
movl $5, %eax
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 3.1 20010315 (experimental)"
>
> Am I missing a GCC command line switch (there are only 472 to choose from
> :-)
>
> Thanks in advance
>
> Dan
>
>
--
Michael Meissner, Red Hat, Inc. (GCC group)
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work: meissner@redhat.com phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org fax: +1 978-692-4482