Forum Discussion
Altera_Forum
Honored Contributor
15 years agoTechnically, changing the cpu's program counter (PC) is easy. You just make a function call to the address of the new code or execute a JMP instruction in assembly. However, there are a lot of other things to take into account like your current stack pointer, heap, hardware state.
Also, how are you going to upload new firmware without simultaneously overwriting the old stuff while you are still running out of it. However, if all you want to do is make a non-returnable jump. Here is a bit of inline assembly: { register unsigned int my_reg; my_reg = (unsigned int)<address_that_I_want_to_jump_to>; __asm__("jmp %0;" :/*no output*/ :"r"(my_reg)); } I'm writing this without reference so I might have some syntax error. An easier method which results in a "CALLR" instruction rather than "JMP" would be: { ((void (*)())<address_that_I_want_to_jump_to>)(); } The latter simply casts your address as a pointer to a function and calls it. However because you are trying to update firmware; before doing either of these, I would ensure that you have disabled interrupts, reduced the stack to it's minimum, free'd any allocated memory, and put any hardware to its initialization state. Jake