RH850 Get PC current address

Hi, I'm trying to read the contents of the PC register in an RH850 uC in C language (GHS compiler), but I haven't found anything about it. The PC register is not mapped to an address. I am no expert in ASM, but the ldsr and stsr opcodes don't provide a way to address the PC register.

Is there an ASM opcode to copy the contents of the PC register to another register?

Please let me know where I can start looking for clues on this.


  • Hi migsantiago,

    I don't know with the GHS compiler but for CC-RH, in assembler, PC cannot be specified as an operand.

    RenesasRulz Forum Moderator


  • Hi, by using the GHS compiler I managed to get the program counter with some assembly code and the Link Pointer. Other compilers may use a different general purpose register for the return value.

    unsigned int get_PC()
    unsigned int link_pointer = 0; //if used as the return value, GHS assigns it as r10
    __asm ( " mov 4, r2 // r2 = 4" );
    __asm ( " mov lp, r10 // r10 = link pointer (r31)");
    __asm ( " sub r2, r10 // r10 = r10 - 4, substract the jumped offset");
    return (link_pointer);

    The link pointer contains the PC from where the get_PC() function was called plus 4 bytes for the return.
  • In reply to migsantiago:

    This is not valid if the compiler inline the function. the better way is to use a software trap, the CPU will save the PC register into EIPC then you can read the PC from EIPC inside the ISR of the trap.