A.2.3 Executing a program in RAM

A program allocated in ROM can be transferred to RAM and executed in RAM.

The attribute of the program to be transferred should be the far attribute.

The default text section with a far attribute is .textf.

If not the whole but only part of the .textf section is to be executed from RAM, use #pragma section to change the section name and specify that section name for the -rom option. After having been transferred from ROM to RAM, the section can be executed from RAM.

 

Example

If an interrupt occurs, f1 and f2 are transferred to RAM and executed in RAM.

-

File : ram.c

#include "iodefine.h"
#pragma section text    ram_text
 
__far void f1(char) {...}
__far int f2(int) {...;f1(x);...}
 
#pragma section
#pragma interrupt       inthandler (vect=INTP0)
 
void inthandler(void){
    /*Program is transferred from the ram_text_f section to the ram_text_fR section*/
        unsigned char __far *dst, *src;
        src = __sectop("ram_text_f");
        dst = __sectop("ram_text_fR");
        while (src < __secend("ram_text_f")) {
                *dst++ = *src++;	  
        }
    /*Call the program that was transferred to RAM*/
        f2(1);
}

-

Link option

-rom=ram_text_f=ram_text_fR
-start=ram_text_f/3000
-start=ram_text_fR/ff000