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

Set program counter

Hi,
how can i set program counter from variable in C code?

void func(void)
{
  uint32_t XADDR;
  XADDR = __current_pc();
  ...
  // need set PC from XADDR
  // msr pc, XADDR not compiled
}

Thanks in advance

Parents
  • You said you wanted to set the PC, returning runs into a whole slew of issues about stack balance, and stuff the compiler expects to be happening.

    You'd be far better of just calling with a function pointer and coming back so you can clean up, rather than hosing the stack and the system up.

    So is it coming back to the point you change the PC, or to the address that called the function that messing up the PC and stack?

    Don't do this in C, do it in assembler where you have some explicit control.

Reply
  • You said you wanted to set the PC, returning runs into a whole slew of issues about stack balance, and stuff the compiler expects to be happening.

    You'd be far better of just calling with a function pointer and coming back so you can clean up, rather than hosing the stack and the system up.

    So is it coming back to the point you change the PC, or to the address that called the function that messing up the PC and stack?

    Don't do this in C, do it in assembler where you have some explicit control.

Children