This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Help with inline assembly.
- To: "'gcc-help at gcc dot gnu dot org'" <gcc-help at gcc dot gnu dot org>
- Subject: Help with inline assembly.
- From: "Tervel Atanassov (Anaheim)" <TAtanassov at printrak dot com>
- Date: Wed, 2 May 2001 15:42:29 -0700
> Dear Helper,
>
> I am having one hell of a time trying to get some information on how to
> program in the gcc assembly. Can you please refer me to a nebie guide or
> or something?
>
> Actually maybe it would be easier if I told you what I want to do.
> In Windows there is a set of API functions which perform atomic "test and
> set"-like operations. They all start with Interlocked. For example there
> is an InterlockedIncrement() which takes a long pointer, locks the bus and
> increments the value. The lock makes the operation atomic over many
> processors. In Linux, I found a header file called "atomic.h" which has
> similar
> functions which start with the word "atomic". For example, atomic_inc().
> The problem I have is that these have a void return value, whereas their
> Windows analogies return the modified value. I am trying to use these
> functions as templates to return the modified value. So I started with
> the
> function:
>
> static __inline__ int atomic_inc_and_test(atomic_t *v)
> {
> unsigned char c;
>
> __asm__ __volatile__(
> LOCK "incl %0; sete %1"
> :"=m" (v->counter), "=qm" (c)
> :"m" (v->counter) : "memory");
> return c != 0;
> }
>
> However -- as you can see -- this does not return the incremented value,
> but
> the result of a boolean expression.
>
> Can you please modify the above code for me so that I can incorporate it
> into my code? Your help is much appreciated.
>
> Sincerely,
>
> Tervel Atanassov
>