5.6 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.

The registers that are special and that are used by the compiler are listed in the following table.

Table 5-10. Registers Used By The Compiler
Register nameApplicable devices
WREGAll 8-bit devices
STATUSAll 8-bit devices
PCLATHAll Mid-range devices
PCL, PCLATH, PCLATUAll PIC18 devices
BSREnhanced Mid-range and PIC18 devices
FSRNon-Enhanced Mid-range devices
FSR0L, FSR0H, FSR1L, FSR1HEnhanced Mid-range and PIC18 devices
FSR2L, FSR2HAll PIC18 devices
TBLPTRL, TBLPTRH, TBLPTRU, TABLATAll PIC18 devices
PRODL, PRODHAll PIC18 devices
btemp, wtemp, ttemp, ltemp, lltempEnhanced Mid-range and PIC18 devices

The xtemp registers are variables that the compiler treats like registers. These registers are saved like any other register if they are used in interrupt code. The lltemp register is only available when using Enhanced Mid-range or PIC18 devices.

The compiler will not be aware of changes to a register’s value when the register itself is used in expressions as a C lvalue (assignment destination), so such statements should be used with caution. For example, if the statement WREG = 0; were encoded using the clrf instruction, the compiler would not consider this as modifying the W register. Additionally, registers should not be changed directly by in-line assembly code, as shown in the following example, which modifies the ZERO bit in the STATUS register using the macro defined by <xc.h>.
#include <xc.h>
void getInput(void)
{
    __asm("bcf " ZERO_bit); //do not write using inline assembly code
    process(c);
}

If any of the applicable registers listed in the table are used by interrupt code, they will be saved and restored when an interrupt occurs, either in hardware or software (see Context Switching).