Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 134
 2012 Microchip Technology Inc.
5.3.3
Device Header Files
There is one header file that is typically included into each C source file you write. The 
file is <xc.h> and is a generic header file that will include other device- and architec-
ture-specific header files when you build your project.
Inclusion of this file will allow access to SFRs via special variables, as well as macros 
which allow special memory access or inclusion of special instructions, like CLRWDT.
Legacy projects may continue to use the <htc.h> header file.
Avoid including chip-specific header files into your code as this will reduce portability.
The header files shipped with the compiler are specific to that compiler version. Future 
compiler versions may ship with modified header files. If you copy compiler header files 
into your project, particularly if you modify these files, be aware that they may not be 
compatible with future versions of the compiler.
For information about assembly include files (.inc), see 
Section 5.12.3.2 “Accessing Registers from Assembly Code”.
5.3.4
Stack
The 8-bit PIC devices use what is referred to in this user’s guide as a hardware stack. 
This stack is limited in depth and cannot be manipulated directly. It is only used for 
function return addresses and cannot be used for program data.
1
 The compiler 
implements a compiled stack for auto variables. See Section 5.5.2.2.1 “Compiled 
Stack Operation”
 for information on how this is achieved.
You must ensure that the maximum hardware stack depth is not exceeded; otherwise, 
code may fail. Nesting function calls too deeply will overflow the stack. It is important to 
take into account implicitly called library functions and interrupts, which also use levels 
of the stack. The compiler can be made to manage stack usage for some devices using 
the stackcall suboption to the --RUNTIME compiler option, see 
Section 4.8.50 “--RUNTIME: Specify Runtime Environment”. This enables an alter-
nate means of calling functions to prevent stack overflow.
A call graph is provided by the code generator in the assembler list file, see 
Section 6.6.6 “Call Graph”. This will indicate the stack levels at each function call and 
can be used as a guide to stack depth. The code generator may also produce warnings 
if the maximum stack depth is exceeded.
Both of these are guides to stack usage. Optimizations and the use of interrupts can 
decrease or increase the stack depth used by a program over that determined by the 
compiler.
1.Microchip 16- and 32-bit devices allow the use of what is referred to in their respective user’s guides
as a software stack. This is the typical stack arrangement employed by most computers and is ordinary
data memory accessed by some sort of push and pop instructions, and a stack pointer register.