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 entire but a part of .textf section is to be executed on RAM, use #pragma section to change the section name and specify the changed section name to ROMize option. The romized section can be executed on RAM after transferring the section to RAM.
Example | If an interrupt occurs, f1 and f2 are transferred to RAM and executed in RAM. |
#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);
}
|
-rom=ram_text_f=ram_text_fR
-start=ram_text_f/3000
-start=ram_text_fR/ff000
|