We have a program which downloads data via serial comms in to RAM. Which is then executed. For easy coding we are using C to code the block of code which is uploaded to the micro's RAM. This block of code changes depending on what is sent down the serial.
In asm instructions we would do the following
ASM:
;[use serial to download set of opcodes into $0100]
;then once download is complete
ORG $0100
;[code stored in memory now runs.]
How would one do this in C? We are having trouble figuring out how to define an 'origin' in C so that this new code that is downloaded into RAM can be run.
We are using a MC9S08GB60A.
Any help will be awesome!
Thanks for the help guys.
Although the address locations need to be modified so that all the REL jumps that the code does, take place in the RAM space you intend to place the code. If this is not done, then the C code will not execute correctly in RAM
Hello,
As Lundin has already indicated, the code being downloaded to the target will need to have been previously compiled and linked so that a binary image of the assembly/machine code is what is sent. Or alternatively, perhaps use S19 format for an ASCII format file, which is easily converted to a binary image, and provides rudimentary error detection.
The linking process will need to be controlled so that the execution location for the code is from the specific block of RAM memory, so that absolute jumps are to the correct address. Relative jumps within the new code are not a problem.
Regards,
Mac
C language supports asm instructions; try:
asm {bsr 0x100;} /* branch to subroutine at 0x100 */
Take care of right syntax - the exmple above is for 9S12.
ipa
Hello
Well according to my understanding you are looking for a way to execute code stored at a specific address in RAM. Am I right?
This can be done defining a constant function pointer and calling the function through the function pointer.
For example:
define the constant function pointer as
void (*const fktPtr)(void) = (void(*)(void))0x100;
in your code add a JSR to the code located at address 0x100:
fktPtr();
CrasyCat