Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 225
5.15.1.2.3
Down the Conveyor Belt and Object files
Once the robot has assembled an order and placed the components in a box, the con-
tents of the box are no longer relevant, and the remaining activities in the warehouse 
only deal with boxes.
It is a similar situation in the compiler: Once assembly code has been placed into a sec-
tion, the instructions are no longer relevant during the link process. The linker only 
handles sections and is oblivious to each section’s contents.
1
5.15.1.2.4
Sorting Boxes and Sections
In the warehouse, all the boxes are sorted by destination city. Once the day’s orders 
have been processed, all these similar boxes are wrapped so they can be easily kept 
together.
The concept is the same in the compiler domain: Sections are sorted based on the sec-
tion’s name, and are merged into one larger section by the linker. The order in which 
the sections come together strictly follows the order in which they are produced.
5.15.1.2.5
Loading the Containers and Classes
In the warehouse, the bundled boxes are loaded into the shipping containers. One or 
more shipping containers will be provided for each country. If there are orders for more 
than one city in the same country, then the bundled boxes for those cities can share the 
same container (as long as there is room).
The linker does a similar thing: It arranges the collated sections in the classes. Typi-
cally, several sections are placed in each class. The classes represent the device mem-
ory, but might take into account addressing modes or banking/paging restrictions 
present in the target device. Classes are often smaller than the memory space in which 
they are theoretically located.
Think of a large cargo ship. Although the ship may be very long, the biggest object it 
can hold is determined by the size of the shipping containers it transports. The shipping 
company may not be able to carry an item due to size constraints even though the item 
is a fraction the size of the vessel.
5.15.1.3
SECTIONS AT WORK
Now that we have a basic understanding of the concepts, let’s work through a simple 
example to help see how these work when compiling.
An engineer has written a program. Exactly what it does or how it is written is not impor-
tant. The target device has only one bank of RAM and one page of flash.
In our very simplified example, the compiler will choose from the sections listed in 
Table 5-15. This table also shows the linker class associated with each section and the 
memory location in the device the class represents.
1.Inside the compiler there are actually a few steps between the code generator and linker. Assembly
code is first passed to the assembler; however, the object files produced, and which are passed to the
linker, preserve all the sections and can be ignored in this exercise.
The assembler optimizer can change alter assembly instructions, but this is only after reading and in-
terpreting the code – something the linker cannot do. Modified code is still functionally identical to the
original. Other optimizations can further merge or split sections, but this is not important in a basic un-
derstanding of the concepts.