On Thu, Sep 27, 2012 at 6:44 AM, jonnyjack <jonnyjack7@xxxxxxxxx> 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