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 which are used by the compiler are listed in the following table.

Table 5-10. Registers Used By The Compiler
Register name Applicable devices
WREG All 8-bit devices
STATUS All 8-bit devices
PCLATH All Mid-range devices
PCL, PCLATH, PCLATU All PIC18 devices
BSR Enhanced Mid-range and PIC18 devices
FSR Non-Enhanced Mid-range devices
FSR0L, FSR0H, FSR1L, FSR1H Enhanced Mid-range and PIC18 devices
FSR2L, FSR2H All PIC18 devices
TBLPTRL, TBLPTRH, TBLPTRU, TABLAT All PIC18 devices
PRODL, PRODH All PIC18 devices
btemp, wtemp, ttemp, ltemp, lltemp Enhanced Mid-range and PIC18 devices

The xtemp registers are variables that the compiler treats as registers. These 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 a C lvalue (assignment destination). For example, if the statement WREG = 0; was encoded using the clrf instruction, the compiler would not consider this as modifying the W register. Nor should these registers be changed directly by in-line assembly code, as shown in the following example which modifies the ZERO bit in the STATUS register.

#include <xc.h>
void getInput(void)
{
    asm("bcf ZERO"); //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 5.9.4 Context Switching).