Keil Logo

Register Bank

The C16x/ST10/XC16x microcontroller families support multiple register banks that must be located in on-chip RAM. The C166 Compiler allows you to define up to 128 register banks of 16 registers (R0-R15). The base address of the currently active register bank is specified in the context pointer (CP) SFR.

If a function is declared with the using attribute, a new register bank is selected on entry to the function and the previous register bank is restored when the function exits. The compiler generates the code necessary to change and restore the register bank.

There are several advantages to using more than one register bank. Using multiple register banks enhances the performance of interrupt procedures and real-time programs. If the active register bank is exchanged when an interrupt or context switch occurs, only the Context Pointer must be saved. Otherwise, the whole register bank must be saved before the interrupt procedure or task can execute.

The using function attribute is used to specify which register bank a function uses. For example:

<[>type<]> funcname (<[>args<]>) using bankname

Where

type is the type of the value returned from the function. If no type is specified, int is assumed.
funcname is the name of the function.
args is the argument list for the function.
using specifies which register bank the function uses.
bankname is the register bank name.

You may use the same register bank in more than one function. It is common practice to use the same register bank name for interrupt procedures defined with the same interrupt priority level. It is possible to use the same name because interrupt functions with the same priority level cannot interrupt each other. Therefore, the register bank is not in use when the interrupt occurs. For example:

void rb_func (void) using my_rbank  {
.
.
.
}

In the above example, using my_rbank specifies that my_rbank is the name of the active register bank during the execution of the function rb_func. There are no restrictions or required naming conventions for the register bank name. Memory for the register bank is automatically allocated and located by the linker.

The using attribute affects the generated object code as follows:

  1. The current CP is saved on the stack when the function is entered.
  2. The CP is set to point to the specified register bank.
  3. When the function exits the saved CP value is restored.

The following listing shows the code generated for the using attribute:

stmt level    source
   1
   2          extern bit alarm;
   3          int alarm_count;
   4          extern void alfunc (bit b0);
   5
   6          void falarm (void) using f_registers  {
   7   1        alarm_count++;
   8   1        alfunc (alarm = 1);
   9   1      }

ASSEMBLY LISTING OF GENERATED OBJECT CODE
             ; FUNCTION falarm (BEGIN  RMASK = @0x3FFF)
0000 F6F00000 R    MOV     f_registers,R0
0004 C6090000 R    SCXT    CP,#f_registers
0008 CC00          NOP
                                           ; SOURCE LINE # 6
                                           ; SOURCE LINE # 7
000A 248F0000 R    SUB     alarm_count,ONES
                                           ; SOURCE LINE # 8
000E 0F00     E    BSET    alarm
0010 CA000000 E    CALLA   cc_UC,alfunc
                                           ; SOURCE LINE # 9
0014 FC09          POP     CP
0016 CB00          RET
             ; FUNCTION falarm (END    RMASK = @0x3FFF)

Note

  • The using attribute is not allowed when declaring or prototypeing external functions. For example, the following function prototype is invalid:
    extern int func (void) using my_regbank;
    
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.