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

From C, inline assembly LJMP to Numerical Address

How do I perform a long jump to a numerical address from my C code?
I'm pretty sure I have to do this with inline assembly - however that
seems complicated for C51. I figured in C I could do this:

typedef void (*jmpPtr)(void);
jmpPtr jmp;

...

unsigned int address = 0x4000U;
jmp = (jmpPtr) address;
(*jmp)();

Except for the call differences, I think this would be the same as doing
a jump to the numerical address? Keil, is this correct?

Parents
  • First, why all the hoops (eg typedef)?

    Just to make it more readable I suppose.

    Setjmp() and longjmp() save the state from one code point to
    another and doesn't allow for specifying an address. The reason
    I need an address is because I am going to dynamically program
    Flash and then execute code out of the just-programmed Flash.

Reply
  • First, why all the hoops (eg typedef)?

    Just to make it more readable I suppose.

    Setjmp() and longjmp() save the state from one code point to
    another and doesn't allow for specifying an address. The reason
    I need an address is because I am going to dynamically program
    Flash and then execute code out of the just-programmed Flash.

Children
  • Just to make it more readable I suppose.

    I'm not sure I'd agree that 5 lines is more readable than 2. To each their own.

    Setjmp() and longjmp() save the state from one code point to
    another and doesn't allow for specifying an address.


    Good point. If you don't like the LCALL then you'll have to use some assembler I'm afraid. How bad is the LCALL implementation for you?

    - Mark