ARM Technical Support Knowledge Articles

Can I use "named registers" to access coprocessor registers?

Applies to: RealView Development Suite (RVDS)


"Named registers" is an RVCT compiler feature allowing you to represent an ARM Architecture register (including ARM coprocessor registers), for example "APSR", as a variable in your C source code. Using named registers can eliminate the need for inline or embedded assembler. The compiler will automatically insert any special instructions required to access the named registers.

For example, this C code to enable interrupts:

register unsigned int apsr __asm("apsr");
apsr = ~(~apsr | 0x40);

will produce the following instruction sequence:

MRS  r0,APSR  ; formerly CPSR
BIC  r0,r0,#0x40
MSR  CPSR_c,r0

Named registers can also be used to access coprocessor registers. 

For example, this C code to enable the MMU using CP15:

register unsigned int cp15_control __asm("cp15:0:c1:c0:0");
cp15_control |= 0x1; 

will produce the following instruction sequence:

MRC  p15,#0x0,r0,c1,c0,#0
ORR  r0,r0,#1
MCR  p15,#0x0,r0,c1,c0,#0

For more details on named register usage please refer to the RVCT Compiler User Guide. Details on available registers for your ARM processor can be found in the relevant Technical Reference Manual. Both these documents are available from the ARM website documentation section.

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential