Quantcast
Channel: x86 Assembly - Programmers Heaven
Viewing all articles
Browse latest Browse all 152

gcc inline assembly and BTS

$
0
0
Hi all,

I am not a x86 assembly programmer myself, however, I need atomic BTS in my C program. I've managed to write the following code, however, the return values are bogus. Any idea where the problem may be?

Thanks.

#include

bool bts (void *mem, int offset)
{
int old;
__asm__ volatile (
"xor %%ecx, %%ecx
"
"lock; bts %1, %2
"
"setc %%cl
"
"mov %%ecx, %%eax
"
: "=a" (old)
: "r" (offset), "m" (mem)
: "memory", "cc", "%ecx");
return old;
}

int main ()
{
unsigned char c = 5;

for (int offset = 0; offset != 8; offset++) {
int old = bts (&c, offset);
printf ("Bit %d has value %d
", offset, old);
}
return 0;
}

Viewing all articles
Browse latest Browse all 152

Trending Articles