Creating Global Register Variables
5-10
5.6 Creating Global Register Variables
The TMS320C2x/C2xx/C5x compiler extends the C language by adding a
special convention to the register keyword to allow the allocation of global reg-
isters. In this special case, the register keyword is treated as a storage class
modifier. The declaration must appear before any function definitions. This
special declaration has the form:
register
type
AR6
or
register
type
AR7
The two registers R6 and R7 are normally save-on-entry registers;
type
cannot
be float or long. When you use the allocation declaration at file level, the regis-
ter is permanently reserved from any other use by the optimizer and code gen-
erator for that file. You cannot assign an initial value to the register. You can
use a #define statement to assign a meaningful variable name to the register
and use the variable normally; for example:
register struct data_struct *AR6
#define data_pointer (AR6)
data_pointer−>element;
data_+;
5.6.1 When to Use a Global Register Variable
There are two reasons that you would be likely to use a global register variable:
-
You are using a global variable throughout your program, and it would sig-
nificantly reduce code size and execution speed to assign this variable to
a register permanently.
-
You are using an interrupt service routine that is executed so frequently
that it would significantly reduce execution speed if the routine did not
have to save and restore the register(s) it uses every time it is executed.
You should consider carefully the implications of assigning a global register
variable. Registers are a precious resource to the compiler, and using this fea-
ture indiscriminately may result in less efficient code.
You should also carefully consider how code with a globally declared register
variable interacts with other code, including library functions, that does not rec-
ognize the restriction placed on the register.
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...