how to get program counter (PC)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to get program counter (PC)

4,598 Views
mikoran
Contributor II
can u help me how to get the value of the program counter?
 
        TFR PC, D
        STD u16pc
 
but it didnt work.
 
tnx.
Labels (1)
5 Replies

1,879 Views
CrasyCat
Specialist III
Hello
 
PC is not a valid operator for the TFR instruction according to the HCS12 core reference manual.
 
Are you using CodeWarrior and programming in assembler?
 
Then I would write the following in your assembly source file:
            LDX #*
 
CrasyCat
0 Kudos
Reply

1,879 Views
mikoran
Contributor II
yes i am using codewarrior but using C. i just add that inline assembly code..
0 Kudos
Reply

1,879 Views
CrasyCat
Specialist III
Hello
 
  I am not sure you can do that in inline assembly.
  May ask you why you need to load the PC in a register?
 
   What are you trying to achieve here?
 
CrasyCat
0 Kudos
Reply

1,879 Views
CompilerGuru
NXP Employee
NXP Employee
I'm wondering just as CrazyCat why you want to retrieve the PC, do you really need it?

If you do need it, see below for one way how to do it.
This snippet gets the PC as it is at the STX instruction, just after the LEAX.

Daniel

Code:
unsigned int pcVar;void test(void) {  __asm {    LEAX 0,PC;    STX pcVar;  }}

 

1,879 Views
mikoran
Contributor II
ok tnx a lot.
I need to retrieve PC for later debugging purposes. I have this module that would record the details during RAM fault
0 Kudos
Reply