Справочник Пользователя для Microchip Technology SW006021-2
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 226
2012 Microchip Technology Inc.
The code generator starts to read the program description in C and produces the
assembly code required to implement this on the target device.
assembly code required to implement this on the target device.
The first thing the code generator encounters is the C definition for a variable with no
initial value. All variables like this will be kept together so that clearing them at startup
will be easier and more efficient. The code generator outputs the directive that starts a
new section. Its internal table of section names indicates that bss0 is the appropriate
choice and that this section is placed in the BANK0 class. The directive looks like this.
initial value. All variables like this will be kept together so that clearing them at startup
will be easier and more efficient. The code generator outputs the directive that starts a
new section. Its internal table of section names indicates that bss0 is the appropriate
choice and that this section is placed in the BANK0 class. The directive looks like this.
PSECT bss0,class=BANK0
Code follows this directive to define the variable: It merely consists of a label and
another directive to reserve the required amount of memory. Altogether, this might look
like:
another directive to reserve the required amount of memory. Altogether, this might look
like:
PSECT bss0,class=BANK0
myVariable:
DS 2 ; reserve 2 bytes for this object
The code generator continues and sees yet another uninitialized variable. As this vari-
able will also use the same section, the code generator can keep adding to the current
section and so immediately outputs another label and directive to reserve memory for
the second variable.
able will also use the same section, the code generator can keep adding to the current
section and so immediately outputs another label and directive to reserve memory for
the second variable.
Now a function definition is encountered in the C source. The code generator sees that
output now needs to be placed in the text section and outputs the following directive.
output now needs to be placed in the text section and outputs the following directive.
PSECT text,class=CODE
This directive ends the bss0 section and starts the text section. Any code following
will be contained in the text section. Code associated with the function is generated
and placed into this section.
will be contained in the text section. Code associated with the function is generated
and placed into this section.
Moving on, the code generator encounters a variable which is initialized with a value.
These variables will have their initial values stored in flash and copied as a block into
the RAM space allocated to them. By using one section for the RAM image and another
for the initial values, the compiler can ensure that all the initial values will align after link-
ing, as the sections will be collated in order.
These variables will have their initial values stored in flash and copied as a block into
the RAM space allocated to them. By using one section for the RAM image and another
for the initial values, the compiler can ensure that all the initial values will align after link-
ing, as the sections will be collated in order.
The compiler first outputs the directive for the section with the name data0. It then out-
puts a label and directive to reserve memory for the variable in RAM. It next changes
to the idata section which will hold all the initial values. Code is output that will place
the initial value in this section. Notice that the code associated with initialized variables
is output into two separate sections.
puts a label and directive to reserve memory for the variable in RAM. It next changes
to the idata section which will hold all the initial values. Code is output that will place
the initial value in this section. Notice that the code associated with initialized variables
is output into two separate sections.
PSECT data0,class=BANK0
_StartCount:
DS 2 ; space in RAM for the variable
PSECT idata,class=CODE
DB 012h ;initial values places as bytes
DB 034h ; which will be copied to RAM later
The code generator reads yet another initialized variable. It selects the data0 section,
outputs the label and memory reservation directive, then selects the idata section and
stores the initial value.
outputs the label and memory reservation directive, then selects the idata section and
stores the initial value.
TABLE 5-15:
SECTION NAMES FOR OUR SIMPLE EXAMPLE
Section name
Contents
Linker class
Memory location
text
Executable code
CODE
Flash
bss0
Variables that need to be cleared
BANK0
RAM
data0
Variables that need to be initialized
BANK0
RAM
idata
Initialized variable’s values
CODE
Flash