Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 181
5.7
REGISTER USAGE
The assembly generated from C source code by the compiler will use certain registers 
in the PIC MCU register set. Most importantly, the compiler assumes that nothing other 
than code it generates can alter the contents of these registers. So if compiler-gener-
ated assembly code loads a register with a value and no subsequent code requires this 
register, the compiler will assume that the contents of the register are still valid later in 
the output sequence.
If any of the applicable registers listed are used by interrupt code, they will be saved 
and restored when an interrupt occurs, either in hardware or software. See 
Section 5.9.3 “Context Switching”.
The registers that are special and which are used by the compiler are listed in Table 5-9
The state of these registers must never be changed directly by C code, or by any 
assembly code inline with C code. The following example shows a C statement and 
inline assembly that violates these rules and changes the ZERO bit in the STATUS reg-
ister.
#include <xc.h>
void getInput(void)
{
ZERO = 0x1;  // do not write using C code
c = read();
#asm
#include <caspic.h>
bcf ZERO_bit  ; do not write using inline assembly code
#endasm
process(c);
}
MPLAB XC8 is unable to interpret the register usage of inline assembly code that is 
encountered in C code. Nor does it associate a variable mapped over an SFR to the 
actual register itself. Writing to an SFR register using either of these two methods will 
not flag the register as having changed and may lead to code failure.
TABLE 5-9:
REGISTERS USED BY THE COMPILER
Applicable devices
Register name
All 8-bit devices
W
All 8-bit devices
STATUS
All mid-range devices
PCLATH
All PIC18 devices
PCLATH, PCLATU
Enhanced mid-range and PIC18 devices
BSR
Non-enhanced mid-range devices
FSR
Enhanced mid-range and PIC18 devices
FSR0L, FSR0H, FSR1L, FSR1H
All PIC18 devices
FSR2L, FSR2H
All PIC18 devices
TBLPTRL, TBLPTRH, TBLPTRU, TAB-
LAT
All PIC18 devices
PRODL, PRODH