I want to set a bit at position p without using btsl instruction with inline asm gcc c code. Using btsl instruction is simple:
int n,p;
scanf("%d%d",&n,&p);
asm("btsl %1, %0"
:"=m"(n)
:"Ir"(p)
:"cc");
I know for setting bit it can be done:
n|=1<<p;
Now, I'm doing so with inline asm:
asm("movl %1, %%eax;"
"movl %2, %%ebx;"
"shl $1, %%ebx;"
"orl %%ebx, %%eax;"
"movl %%eax, %0;"
:"=b"(n)
:"a"(n), "b"(p)
:"cc");
printf("%d\n",n);
It seems to me shl instruction doesn't work. For instance n=20=10100. When I try to set the first bit p=1 the result is 22=10110 instead of 21=10101