Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 219
5.14.4.9
THE #PRAGMA REGSUSED DIRECTIVE
The #pragma regsused directive allows the programmer to indicate register usage 
for functions that will not be “seen” by the code generator, for example if they were writ-
ten in assembly code. It has no effect when used with functions defined in C code, but 
in these cases the register usage of these functions can be accurately determined by 
the compiler and the pragma is not required.
The compiler will determine only those registers and objects which need to be saved 
for an interrupt function defined and use of this pragma allows the code generator 
to also determine register usage for routines written in assembly code.
The general form of the pragma is:
#pragma regsused routineName registerList
where 
routineName
 is the C equivalent name of the function or routine whose register 
usage is being defined, and 
registerList
 is a space-separated list of registers 
names, as shown in Table 5-9.
Those registers not listed are assumed to be unused by the function or routine. The 
code generator may use any of these registers to hold values across a function call. 
Hence, if the routine does in fact use these registers, unreliable program execution may 
eventuate.
The register names are not case sensitive and a warning will be produced if the register 
name is not recognized. A blank list indicates that the specified function or routine uses 
no registers. If this pragma is not used, the compiler will assume that the external func-
tion uses all registers.
For example, a routine called _search is written in PIC18 assembly code. In the C 
source, we may write:
extern void search(void);
#pragma regsused search wreg status fsr0
to indicate that this routine used the W register, STATUS and FSR0. Here, FSR0 
expands to both FSR0L and FSR0H. These could be listed individually, if required.
5.14.4.10 THE #PRAGMA SWITCH DIRECTIVE
Normally, the compiler chooses how switch statements will be encoded to produce 
the smallest possible code size. The #pragma switch directive can be used to force 
the compiler to use a different coding strategy.
The general form of the switch pragma is:
#pragma switch switchType
where switch_type is one of the available switch types (the only switch type currently 
implemented for PIC18 devices is space) listed in Table 5-14. 
TABLE 5-14:
SWITCH TYPES
switch type
 description
speed
Use the fastest switch method
space
Use the smallest code size method
time
Use a fixed delay switch method
auto
Use smallest code size method (default)
direct 
(deprecated)
Use a fixed delay switch method
simple 
(deprecated)
Sequential xor method