using asm() to execute an atomic subtraction instruction

jonnyjack jonnyjack7@gmail.com
Thu Sep 27 19:50:00 GMT 2012


Thanks! Changing the order of the operands worked, the destination was the
second operand.

On Thu, Sep 27, 2012 at 2:25 PM, Ian Lance Taylor-3 [via gcc] <
ml-node+s1065356n873142h84@n5.nabble.com> wrote:

> On Thu, Sep 27, 2012 at 6:44 AM, jonnyjack <[hidden email]<http://user/SendEmail.jtp?type=node&node=873142&i=0>>
> wrote:
>
> > For a school project, I have to implement a simple atomic_sub() function
> in
> > c.  The implementation must use the asm() function.
> >
> > Right now, my code looks like this
> >
> > void atomic_sub( int * value, int dec_val) {
> >    asm ("LOCK SUB (%0), %1;\n"
> >            :
> >            : "r" (value), "r" (dec_val)
> >            : "memory");
> > }
> >
> > The intention is for "value" to decrement by "dec_val" atomically, but
> when
> > I try to compile I get the following error.
> >
> > "locking.c:28: Error: expecting lockable instruction after 'lock'"
> >
> > This asm() call is on line 28, so this is the instruction the error is
> > referring to.  Does anyone know why this isn't a lockable instruction?
> > According to the documentation from Intel I've read, a sub with a
> > destination of a memory address is lockable.  Any ideas?
>
> You are running into syntax issues.  You are using Intel syntax and
> the assembler is probably expecting AT&T syntax.  You could try the
> -masm=intel option.  Or reverse the operands.
>
> Ian
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://gcc.1065356.n5.nabble.com/using-asm-to-execute-an-atomic-subtraction-instruction-tp873076p873142.html
>  To unsubscribe from using asm() to execute an atomic subtraction
> instruction, click here<http://gcc.1065356.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=873076&code=am9ubnlqYWNrN0BnbWFpbC5jb218ODczMDc2fDQ4ODAyMjI3OQ==>
> .
> NAML<http://gcc.1065356.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://gcc.1065356.n5.nabble.com/using-asm-to-execute-an-atomic-subtraction-instruction-tp873076p873158.html
Sent from the gcc - Help mailing list archive at Nabble.com.



More information about the Gcc-help mailing list