Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

MPLAB
®
XC16 C Compiler Users Guide
DS50002071C-page 174 2012-2013 Microchip Technology Inc.
12.3 CHANGING REGISTER CONTENTS
The assembly generated from C source code by the compiler will use certain registers
that are present on the 16-bit device. Most importantly, the compiler assumes that noth-
ing other than code it generates can alter the contents of these registers. So if the
assembly loads a register with a value and no subsequent code generation requires
this register, the compiler will assume that the contents of the register are still valid later
in the output sequence.
The registers that are special and which are managed by the compiler are: W0-W15,
RCOUNT, STATUS (SR), PSVPAG and DSRPAG. If fixed point support is enabled, the
compiler may allocate A and B, in which case the compiler may adjust CORCON.
The state of these register must never be changed directly by C code, or by any assem-
bly code in-line with C code. The following example shows a C statement and in-line
assembly that violates these rules and changes the ZERO bit in the STATUS register.
#include <xc.h>
void badCode(void)
{
asm (mov #0, w8);
WREG9 = 0;
}
The compiler is unable to interpret the meaning of in-line assembly code that is encoun-
tered 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.

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh