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

Accesing R15 (PC)

Using the GNU Tools, i can output the value of PC (R15) using the following code:

//Declaring Variable
register unsigned int R15 asm ("pc");

//Outputing the value
printf("The Current location of the Program Counter is : 0x%08X\n","PC");

When I change to using Keil Tools however, this no longer works, I get errors with the variable definition. Does anyone know how I can make this work using the Keil compiler Tools?

Parents Reply Children
  • The following is the c file, this compiles and runs fine with GNU tools:

    #include <ADuC7026.h>
    #include<stdio.h>

    // Program Counter Defintion. Allows us to access R15.

    register unsigned int R15 asm ("pc");

    // Function Prototype with required function attribute.

    extern void Ram_Function(void) __attribute__ ((section (".ram_func")));

    int main(void)
    {
    // Setup tx & rx pins on P1.0 and P1.1
    GP1CON = 0x011;
    // Set UART to 9600bps 8-N-1
    COMCON0 = 0x80; // Setting DLAB
    COMDIV0 = 0x93;
    COMDIV1 = 0x00;
    COMCON0 = 0x07; // Clearing DLAB

    //Print current program counter address ... currently executing from FLASH!!
    printf("This is the main Flash Function.\n");
    printf("The Current location of the Program Counter is : 0x%08X\n",R15);
    Ram_Function();

    return 0;
    }

    The output via serial cable is:

    This is the main Flash Function.
    The Current location of the Program Counter is : 0x0008024B


    This address is correct. When i compile this c file using the Keil Tools however, i get the following error message:

    register unsigned int R15 asm ("pc");

    I have called the function from assembley as described by Matthias above and this does work under Keil tools. Is there a way i can get it working without javing to do this though?

  • Apologies, the original line i posted:

    printf("The Current location of the Program Counter is : 0x%08X\n","PC");

    was incorrect, it should have read

    printf("The Current location of the Program Counter is : 0x%08X\n",R15);

    i had changed the line as an experiment to try get the code working and forgot to change it back