linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* c inline assembly
       [not found] <CAGZFCEEaJ7ZsNAmWCF-nDtsjs70U7fqEVvTXEaCt9Tmk1dcemQ@mail.gmail.com>
@ 2012-02-18  6:01 ` ratheesh kannoth
  2012-02-19  5:14   ` Ian Lance Taylor
  2012-02-19 16:46   ` Gedare Bloom
  0 siblings, 2 replies; 4+ messages in thread
From: ratheesh kannoth @ 2012-02-18  6:01 UTC (permalink / raw)
  To: linux-c-programming, gcc-help

I am using gcc on a 32bit  intel machine.  i have defined an inline function.


This function is inline .  what all registers needs to pushed and
poped in the inline assembly so that the functions wont
disturb the registers in  the function ( in which it is C inlined  ).


inline unsigned long hello(unsigned long a)

{
 int b;
 asm ("movl %1, %%eax;
      " movl %1, %%ebx;
       "movl  %1, %%ecx;
       "movl  %1, %%esi;
       "movl  %1, %%edi;

       "movl %%eax, %0;"
       :"=r"(b)        /* output */
       :"r"(a)         /* input */
 );
}
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c inline assembly
@ 2012-02-18  6:26 Vladimir Murzin
  0 siblings, 0 replies; 4+ messages in thread
From: Vladimir Murzin @ 2012-02-18  6:26 UTC (permalink / raw)
  To: ratheesh kannoth, linux-c-programming-owner, linux-c-programming,
	gcc-help

Hi!

What is you question or request? ;-)

------Original Message------
From: ratheesh kannoth
Sender: linux-c-programming-owner@vger.kernel.org
To: linux-c-programming@vger.kernel.org
To: gcc-help@gcc.gnu.org
Subject: c inline assembly
Sent: 18 Feb 2012 10:01

I am using gcc on a 32bit  intel machine.  i have defined an inline function.


This function is inline .  what all registers needs to pushed and
poped in the inline assembly so that the functions wont
disturb the registers in  the function ( in which it is C inlined  ).


inline unsigned long hello(unsigned long a)

{
 int b;
 asm ("movl %1, %%eax;
      " movl %1, %%ebx;
       "movl  %1, %%ecx;
       "movl  %1, %%esi;
       "movl  %1, %%edi;

       "movl %%eax, %0;"
       :"=r"(b)        /* output */
       :"r"(a)         /* input */
 );
}
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Best wishes,
Vladimir Murzin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c inline assembly
  2012-02-18  6:01 ` c inline assembly ratheesh kannoth
@ 2012-02-19  5:14   ` Ian Lance Taylor
  2012-02-19 16:46   ` Gedare Bloom
  1 sibling, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2012-02-19  5:14 UTC (permalink / raw)
  To: ratheesh kannoth; +Cc: linux-c-programming, gcc-help

ratheesh kannoth <ratheesh.ksz@gmail.com> writes:

> This function is inline .  what all registers needs to pushed and
> poped in the inline assembly so that the functions wont
> disturb the registers in  the function ( in which it is C inlined  ).

Your asm statement should list the registers that it clobbers.

One i386 you normally can not clobber %ebp.  When compiling with
-fpic/-fPIC you normally can not clobber %ebx.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c inline assembly
  2012-02-18  6:01 ` c inline assembly ratheesh kannoth
  2012-02-19  5:14   ` Ian Lance Taylor
@ 2012-02-19 16:46   ` Gedare Bloom
  1 sibling, 0 replies; 4+ messages in thread
From: Gedare Bloom @ 2012-02-19 16:46 UTC (permalink / raw)
  To: ratheesh kannoth; +Cc: linux-c-programming, gcc-help

On Sat, Feb 18, 2012 at 1:01 AM, ratheesh kannoth
<ratheesh.ksz@gmail.com> wrote:
> I am using gcc on a 32bit  intel machine.  i have defined an inline function.
>
>
> This function is inline .  what all registers needs to pushed and
> poped in the inline assembly so that the functions wont
> disturb the registers in  the function ( in which it is C inlined  ).
>
Use the clobber list:
http://ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#ss5.3

>
> inline unsigned long hello(unsigned long a)
>
> {
>  int b;
>  asm ("movl %1, %%eax;
>      " movl %1, %%ebx;
>       "movl  %1, %%ecx;
>       "movl  %1, %%esi;
>       "movl  %1, %%edi;
>
>       "movl %%eax, %0;"
>       :"=r"(b)        /* output */
>       :"r"(a)         /* input */
         : "eax","ecx","esi","edi" /* clobber */
>  );
> }
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-19 16:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAGZFCEEaJ7ZsNAmWCF-nDtsjs70U7fqEVvTXEaCt9Tmk1dcemQ@mail.gmail.com>
2012-02-18  6:01 ` c inline assembly ratheesh kannoth
2012-02-19  5:14   ` Ian Lance Taylor
2012-02-19 16:46   ` Gedare Bloom
2012-02-18  6:26 Vladimir Murzin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).