SW006012 Microchip Technology, SW006012 Datasheet - Page 77

C COMPILER FOR DSPIC30F FAMILY

SW006012

Manufacturer Part Number
SW006012
Description
C COMPILER FOR DSPIC30F FAMILY
Manufacturer
Microchip Technology
Type
MPLAB® C30 Compilerr
Series
PIC24 & DsPICr
Datasheets

Specifications of SW006012

Supported Families
PIC24, DsPIC30F And DsPIC33F
Core Architecture
PIC, DsPIC
Kit Contents
Software And Docs
Mcu Supported Families
PIC24 MCUs And DsPIC DSCs
Tool Type
Compiler
Processor Series
PIC24, dsPIC
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
dsPIC30F
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
4.8
© 2007 Microchip Technology Inc.
LOCATING CODE AND DATA
MPLAB C30 C Compiler Runtime Environment
As described in Section 4.4 “Code and Data Sections”, the compiler arranges for
code to be placed in the .text section, and data to be placed in one of several named
sections, depending on the memory model used and whether or not the data is
initialized. When modules are combined at link time, the linker determines the starting
addresses of the various sections based on their attributes.
Cases may arise when a specific function or variable must be located at a specific
address, or within some range of addresses. The easiest way to accomplish this is by
using the address attribute, described in Section 2.3 “Keyword Differences”. For
example, to locate function PrintString at address 0x8000 in program memory:
int
Likewise, to locate variable Mabonga at address 0x1000 in data memory:
int
Another way to locate code or data is by placing the function or variable into a
user-defined section, and specifying the starting address of that section in a custom
linker script. This is done as follows:
1. Modify the code or data declaration in the C source to specify a user-defined
2. Add the user-defined section to a custom linker script file to specify the starting
For example, to locate the function PrintString at address 0x8000 in program
memory, first declare the function as follows in the C source:
int __attribute__((__section__(".myTextSection")))
PrintString(const char *s);
The section attribute specifies that the function should be placed in a section named
.myTextSection, rather than the default .text section. It does not specify where
the user-defined section is to be located. That must be done in a custom linker script,
as follows. Using the device-specific linker script as a base, add the following section
definition:
.myTextSection 0x8000 :
This specifies that the output file should contain a section named .myTextSection
starting at location 0x8000 and containing all input sections named.myTextSection.
Since, in this example, there is a single function PrintString in that section, then the
function will be located at address 0x8000 in program memory.
Similarly, to locate the variable Mabonga at address 0x1000 in data memory, first
declare the variable as follows in the C source:
int __attribute__((__section__(".myDataSection"))) Mabonga =
1;
{
} >program
section.
address of the section.
__
__
attribute
attribute
*(.myTextSection);
__
__
((address(0x8000))) PrintString (const char *s);
((address(0x1000))) Mabonga = 1;
DS51284F-page 71

Related parts for SW006012