Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22162

c inline assembly getting "operand size mismatch" when using cmpxchg

$
0
0

I'm trying to use cmpxchg with inline assembly through c. This is my code:

static inline intcas(volatile void* addr, int expected, int newval) {    int ret;    asm volatile("movl %2 , %%eax\n\t""lock; cmpxchg %0, %3\n\t""pushfl\n\t""popl %1\n\t""and $0x0040, %1\n\t"                : "+m" (*(int*)addr), "=r" (ret)                : "r" (expected), "r" (newval)                : "%eax"                );    return ret;}

This is my first time using inline and i'm not sure what could be causing this problem.I tried "cmpxchgl" as well, but still nothing. Also tried removing the lock.I get "operand size mismatch". I think maybe it has something to do with the casting i do to addr, but i'm unsure. I try and exchange int for int, so don't really understand why there would be a size mismatch.This is using AT&T style.Thanks


Viewing all articles
Browse latest Browse all 22162

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>