Relocating Function in ROM

To put code in a specific memory section it is needed first to create the section using the section pragma directive. In the following listing a new section called .romsymbols is created.

All the content in this section is going to be referenced in the LCF with the name .romsymbols. After defining a new section you can place code in this section by using the __declspec() directive.

In the following listing, __declspec() directive is used to tell the compiler that function funcInROM() is going to be placed in section romsymbols.

Create a stationary project for any target and add the following code to your main.c file before the main() function and have a call to this function.

Listing 1. Code to add in the main.c
#pragma section RX ".romsymbols" data_mode=far_abs 
__declspec(section ".romsymbols") void funcInROM(int flag);    //Function Prototype

 void funcInROM(int flag){

if (flag > 0)

{

flag ++;

}

}