I'm trying to use extended assembly on MacOS (Apple M1). I run into a very un-understandable issue, here is my code :
#include <stdio.h>
int main(void)
{
int a = 1;
int b = 0;
printf("%d\n", a);
printf("%d\n", b);
asm (
" mov x1, x1"
: "=r" (b)
: "r" (a));
printf("%d\n", a);
printf("%d\n", b);
return 0;
}
Here is the result of it :
❯ make && ./hello_world_asm
gcc -c -o hello_world_asm.o hello_world_asm.c
gcc -Wall hello_world_asm.c -o hello_world_asm
1
0
1
1
How is that possible? I really don't get it. I don't even use the registers bounded to a and b but still, b is taking a's value.
I tried to change the inner assembly, if I don't directly put any value in the %0 (b bounded register), it'll just take a's.