Mail Archives: djgpp/1998/09/09/08:56:37
Endlisnis <s257m AT unb DOT ca> wrote:
> Eli Zaretskii wrote:
> >
> > On Mon, 7 Sep 1998, Endlisnis wrote:
> >
> > > > * Post the complete asm produced.
> > > I don't know how to do that.
> >
> > Add -S to the compilation switches.
>
> OK, Here is the input file, which seems to compile differently when giving asm
> output, but it still isn't right! And included is the complete asm output, I
> marked the place where it screws up, in the add function. Is there something
> I'm doing wrong?
>
> #include <iostream.h>
>
> int add(int a, int b)
> {
> int Ret;
> asm ("addl %1, %0" //this line compiles to "addl ecx,ecx".
> : "=&r" (Ret)
> : "0" (a), "r" (b)
> );
> return Ret;
> }
I guess that's just an example, no? There is no need for such a routine.
Anyways ... it doesn't look right try it:
int add(int a,int b)
{
int ret;
asm ("movl %2,%0; addl %1,%0" : "rm="(ret) : "r"(b), "r"(a));
return ret;
}
Compiled with -O2 gives
.file "p.c"
gcc2_compiled.:
___gnu_compiled_c:
.text
.p2align 2
.globl _add
_add:
pushl %ebp
movl %esp,%ebp
movl 12(%ebp),%edx
movl 8(%ebp),%ecx
/APP
movl %ecx,%eax; addl %edx,%eax
/NO_APP
leave
ret
But again isn't a good idea a rotine to make just a simple add because gcc
will do it pretty well alone.
SET
------------------------------------ 0 --------------------------------
Visit my home page: http://set-soft.home.ml.org/
or
http://www.geocities.com/SiliconValley/Vista/6552/
Salvador Eduardo Tropea (SET). (Electronics Engineer)
Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org
ICQ: 2951574
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA
TE: +(541) 759 0013
- Raw text -