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

製品コード
SW006021-1
ページ / 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 218
 2012 Microchip Technology Inc.
So it is allocated to a textn psect. The source code for the masher() function is 
removed from this source file and placed in is own file. The psect pragma is then 
applied so that this new file contains the following.
#pragma psect text%%u=myMasherPsect
int masher(int val)
{
return val;
}
After recompiling, the function is now located in its own psect. The updated map file 
now shows the following. Note that its address has not changed.
                                  Symbol Table
_getInput             text13        07E5
_init                 text12        07E4
_main                 maintext      07ED
_masher               myMasherPsect 07E8
...
The programmer now uses the driver option -L-pmyMasherPsect=1000h to locate 
this psect at the desired location. After recompiling, the map file now shows the follow-
ing. Note that the addresses of other functions have not been affected by the pragma 
in this example.
                                  Symbol Table
_getInput             text13        07E5
_init                 text12        07E4
_main                 maintext      07ED
_masher               myMasherPsect 1000
...
Variables can also be placed at specific positions by making them absolute, see 
Section 5.5.4 “Absolute Variables”. The same is also true for functions. See 
5.8.4 “Changing the Default Function Allocation”. The decision whether functions 
or variables should be positioned using absolutes or via the psect pragma should be 
based on the location requirements.
Using absolute functions and variables is the easiest method, but only allows place-
ment at an address which must be known prior to compilation. The psect pragma is 
more complex, but offers all the flexibility of the linker to position the new psect into 
memory. For example, you can specify that functions or variables reside at a fixed 
address, or that they be placed after other psects, or that the psect be placed anywhere 
in a compiler-defined or user-defined range of address. See Chapter 7. “Linker” for 
the features and options available when linking. See also 4.8.7 “-L-: Adjust Linker 
Options Directly”
 for
 information on controlling the linker from the driver or in MPLAB 
IDE.