Keil™, An ARM® Company

RealView Compiler User's Guide

Named register variables

3.1.5. Named register variables

The compiler enables you to access registers of an ARM architecture‑based processor using named register variables.

Named register variables are declared by combining the register keyword with the __asm keyword. The __asm keyword takes one parameter, a character string, that names the register. For example, the declaration:

register int foo __asm("r0");

declares foo as a named register variable for the register r0. See Named register variables in the Compiler Reference Guide for more information on the registers of ARM architecture‑based processors that can be accessed using named register variables.

A typical use of named register variables is to access bits in the Application Program Status Register (APSR). Example 3-3 shows the use of named register variables to set the saturation flag Q in the APSR.

Example 3.2. Setting bits in the APSR using a named register variable

#ifndef __BIG_ENDIAN // bitfield layout of APSR is sensitive to endianness

typedef union
{
    struct
    {
        int mode:5;
        int T:1;
        int F:1;
        int I:1;
        int _dnm:19;
        int Q:1;
        int V:1;
        int C:1;
        int Z:1;
        int N:1;
    } b;
    unsigned int word;
} PSR;

#else /* __BIG_ENDIAN */

typedef union
{
    struct
    {
        int N:1;
        int Z:1;
        int C:1;
        int V:1;
        int Q:1;
        int _dnm:19;
        int I:1;
        int F:1;
        int T:1;
        int mode:5;
    } b;
    unsigned int word;
} PSR;

#endif /* __BIG_ENDIAN */

register PSR apsr __asm("apsr");

void set_Q(void)
{
    apsr.b.Q = 1;
}
Copyright © 2007 ARM Limited. All rights reserved.ARM DUI 0375A