Originally Posted by
krkr
So r9 register will act as a pointer, what ever value we assign to ptr will be stored in r9 register.
The point here is that "register" keyword isn't a modifier to garantee register allocation... The semantics is "you cannot get the address-of this identifier"...
And, using the GCC extension to allocate a local variable in a specific register is only a hint that can be ignored:
Code:
unsigned long f( unsigned long *p, unsigned int count )
{
unsigned long sum = 0;
unsigned long *q asm ("r9");
q = p;
while ( count-- )
sum += *q++;
return sum;
}
Compiing (SysV x86-64 ABI):
Code:
$ cc -O2 -c test.c
test.c: In function ‘f’:
test.c:4:18: warning: ignoring asm-specifier for non-static local variable ‘q’
unsigned long *q asm ( "r9" );
^
The created code:
Code:
f:
test esi,esi
lea eax,[rsi-1]
je .L4
lea rdx,[rdi+rax*8+8]
xor eax,eax
.L3:
add rax,[rdi]
add rdi,8
cmp rdi,rdx
jne .L3
ret
.L4:
xor eax,eax
ret
Where is r9? If you don't use -O2 option, the compiler will, still, ignore the hint. Try it.