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