User manual

MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 228 2012 Microchip Technology Inc.
The compiler can, and often does, use more than one class to represent the same
memory range. This is illustrated in Section 5.15.1.5 “More Advanced Sections at
Work where the example uses CODE and CONST classes for flash memory. Although
classes may cover the same range, typically the size of the containers vary. This allows
code with different restrictions and requirements to be accommodated.
When the memory ranges of classes overlap, allocating to one will also mark as being
used memory from the other. In fact, when any memory is allocated by the linker by
whatever means, it checks each class to see if it covers this memory and marks it as
being used. This is quite a difference concept to physical containers.
5.15.1.4.3 Multi-bin containers
Linker classes usually define one memory range, but there are instances where a class
defines multiple memory ranges. You can think of this as several separate containers,
but all with identical shipping destinations. Memory ranges in the class do not need to
be contiguous.
The compiler typically uses a multi-range class to represent program memory that is
paged. The boundaries in the memory ranges coincide with the page boundaries. This
prevents sections from crossing a page boundary.
The compiler could use a similar class for banked RAM, but code can be considerably
reduced in size if the destination bank of each variable is known by the code generator.
You will usually see a separate class defined for each bank, and dedicated sections
that are associated with these classes. The code generator will allocate a bank for each
variable and choose a section destined for the class that represents that bank.
5.15.1.5 MORE ADVANCED SECTIONS AT WORK
Let’s build on the previous example. Our target device now has two banks of RAM and
two pages of flash, and Table 5-16 shows the extended list of sections the compiler now
uses. These sections reference new classes, also shown in the table.
The compiler operates as it did in the previous example, selecting and producing a sec-
tion directive prior to generating the assembly code associated with the C source cur-
rently being compiled.
TABLE 5-16: SECTION NAMES FOR OUR EXTENDED EXAMPLE
Section name Contents Linker class Memory location
textn Executable code CODE Flash
bss0 Variables that need to be cleared BANK0 RAM
bss1 Variables that need to be cleared BANK1 RAM
data0 Variables that need to be initialized BANK0 RAM
idata Initialized variable’s values CODE Flash
reset_vec Code associated with Reset CODE Flash
const Read-only variables CONST Flash
init Runtime startup code CODE Flash
int_text Interrupt function code CODE Flash