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?
I can't help you with any ARM specific stuff, but I can tell you that this doesn't seem right (unless it is some kind of bizarre extension to ANSI 'C'): printf("The Current location of the Program Counter is : 0x%08X\n","PC"); You are passing printf() a string when it expects an unsigned int.
PC is the variable corresponding to the Program Counter, it holds the current location in memory that the code is executing from. The overall program works fine in GUN, its just when i switch to the Keil compiler, i cant access this register to output it
*GNU, not GUN, sorry
I'm unclear if you are able to compile the program or not, if you are can you show the exact output you are getting from this line under Keil: printf("The Current location of the Program Counter is : 0x%08X\n","PC");
My approach would look like this:
int getPC (void) { int RetVal; __asm { MOV R0,LR STAV R0,R1,RetVal } return (RetVal); } ... printf ("The current location of the Program Counter is 0x%08X\n", getPC());
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