Sorry, I should have explained better. What I would like to do is copy the code for a function into RAM from another function and then jump to that location in RAM. Is there another way to do it "automatically" (meaning to do it in code without having to look at the compiled code size, then hardcoding the size in) and without having to copy the whole compiled file module into RAM? Is there a way to get the address of a label? Below is a better concept of what I would like to do (do_some_stuff(), etc are just for conciseness--the real code doesn't call any functions). If I could do it this way, does C guarantee that the function's compiled code will lay consecutively between the start of the function and the location pointed to by the end label?
#define RAM_TOP 0x10AF //S08DZ60 ram top? bottom?
unsigned int code_size = 0;
__label__ function_end; //pretending for now that there is such a thing as "global labels"
void function1(void)
{
do_some_stuff();
while(1)
{
do_some_more_stuff();
}
function_end:
;
}
void function2(void)
{
unsigned int i;
unsigned int* ram_start;
extern __label__function function_end;
code_size=&function1 - &function_end;
ram_start = RAM_TOP-(code_size+1);
for(i=0; i< code_size; i++)
{
*(ram_start++)=*(&function1++);
}
}
This won't work, but is there an easier/better/cleaner way to do it (one that actually works)?