This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Switching between code programs

I have two different code programs: Program "B" which is located at 1000h and Program "A" located at 0h (it ends before 1000h) and it's working properly. How can I start executing program "B" from Program "A". I have tried this software reset but it doesn't work:

((void  (code *)  (void)) 0x01000) ();
Note: there is no need for sharing data between programs. I just need to switch between executing one program or another

  • What do you mean by "program"? Just some code to execute, or a complete system including interrupt vectors for interrupt handlers, and so on?

    The reset always begins execution at 0, and the interrupt vector table always occupies the bottom of memory. You can't really reset into a different memory location without some bank-switching hardware. You could, however, update the code at address 0 (which typically just jumps to the start of "the" program) before you reset, at least if your vector table in in RAM and the reset will preserve the RAM contents.

    The code snippet you post will call a function at address 0x1000. This will leave a return address on the stack, which is probably not what you want if the code never returns. I'd just write a little assembler function that adjusts the stack and then jumps to 1000H.

  • Thank for your reply Drew Davis,
    Actually what I want to do is to execute a separate code (a complete system) from my application. The problem is that I don't have the source code for that "separate code". So my idea is in somehow to place the code (the one I don't have the source code) in a empty space of the memory and then try to invoke it from my application. Do you think there is a way to do this?
    Than you very much.

  • Do you think there is a way to do this?

    No. Not if you're moving the code from its real address to some other position in memory. That cannot possibly work, because 8051 isn't position-independent. And that's before we even begin to look at what usage of data memory that code may have, which the .hex file you have will tell you nothing about.