How to Relocate Code in RAM

The following listings provide sample code examples to relocate the code in RAM.

Listing 1. Sample code in the source file
#pragma section ".myCodeInRAM" code_mode=far_abs

__declspec(section ".myCodeInRAM") int _add(int a , int b);

int main(void) {

  volatile int i = 0;

  volatile int total = 0;

    /* Loop forever */

  for (;;)  {

      total = _add(i , i);

    i++;

  }

}

__declspec(section ".myCodeInRAM") int _add(int a , int b)

{

    return a + b;

}

Listing 2. Sample code in the lcf file
MEMORY

{

   .............

    /* SRAM: 0x40000000 - 0x4000FFFF */

    internal_ram:          org = 0x40000000,   len = 0x0000D000

    myram:                 org = 0x4000D000,   len = 0x00001000

  ...............

}

..........

    GROUP : {

       .my_ram (VLECODE) : {          //VLECODE- if the code is the generated for VLE mode

          *(.myCodeInRAM)

         }

    } > myram

.................