cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the PC(Program counter) register?

nicolas_homeostasie
Associate II
Posted on January 09, 2008 at 04:42

Getting the PC(Program counter) register?

3 REPLIES 3
nicolas_homeostasie
Associate II
Posted on January 08, 2008 at 10:47

Hi,

Again another message. I would like to know if it is possible to get the PC register thanks to assembler commands.

Below, what i have done:

Code:

unsigned char cNbOctet = 0;

asm

{

LD A,PCL;

LD cNbOctet, A;

}

But my compiler detect one error: Label Adressing Not Supported.

Why?

According to the st7 datasheet, pc is a 16-bit register containing the address of the next instruction to be executed by the CPU. It is made of two 8-bit registers PCL (Program Counter Low which is the LSB) and PCH

(Program Counter High which is the MSB).

Thanks for your help.

Nicolas

fggnrc
Associate II
Posted on January 09, 2008 at 04:10

Nicolas,

there is no assembler instruction to read the program counter register value (of course, the jump or call instructions change its value, but this is not what you ask).

To have the program counter value, one have to use a subroutine call which pushes on the stack the return address (i.e. the program counter of the next istruction to execute when the subroutine ends). If you know this, in the subroutine code you can use the following instructions:

POP X ; X = PCH

POP A ; A = PCL

PUSH A ; Restore the stack content

PUSH X

RET

When the above subroutine returns, the pair {X,A} holds the program counter of the first instruction after the subroutine call.

I hope I was helpful...

Regards,

EtaPhi

PS: what do you plan to do with the program counter? Perhaps there is a simpler way to obtain what you need...

nicolas_homeostasie
Associate II
Posted on January 09, 2008 at 04:42

EtaPhi,

Thanks for your reply. In fact, i would like to get the PC register so as to verify its actual value. To debug a problem, I would check if my PC is not corrupted inside a while operation. But i feel that is not the best way...

Regards,

Nicolas