As per my understanding, answer is YES and NO.
NO because,
Any array element must be explicitly addressable (i.e. for eg. for 16 bit uC/uP its address should always lie between 0x0000 to 0xFFFF address space.)
CPU registers are accessed using register direct addressing mode ( such as mov r2,#100 ).
This addressing mode does not have an effective address. ( even it is not considered to be an addressing mode )
Array elements must reside in continous memory locations. ( for pointer arithmetic, the main reason to use array )
and YES because,
- Compiler can allocate register for above array, so that we can perform some limited operations on it.
But operations which internally uses address for optimizations can't be used.
See below code.
int main( )
{
register int arr[4];
int i;
arr[0] = 10; /* OK */
arr[1] = 20; /* OK */
arr[2] = 30; /* OK */
arr[3] = 40; /* OK */
for(i=0;i<4;i++)
arr[i]=10; /* Error : "address of register variable 'arr' requested" */
return 0;
}
So my final conclusion is that, ideally register storage class should never be used with array even if your compiler permits it.
Please correct me or give more inputs. :-)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…