I want to read a register named x0 in arm64 (not x86_64) using C language. What's the best way (bug free and portability?)
I search all the network, I just find some ways:
register int *foo asm ("a5"); //1
register int foo asm ("a5"); //2 which right?
or
intptr_t sp;
asm ("movl %%esp, %0" : "=r" (sp) ); //3
The first way have some bugs I think. x0 in arm64 is 64bit. I think int *f can not hold the 64 bit addr.
The second way is for x86. It seem not work make it in this way:
asm ("movl %x0, %0" : "=r" (sp) );
So what's the correct way read a register in C