avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: [avr-gcc-list] reading program counter


From: Stumpf Michael
Subject: AW: [avr-gcc-list] reading program counter
Date: Wed, 6 Nov 2002 08:27:21 +0100

Hi,
>
> How can I read the program counter in a u16 variable?
> I have read the d.s but haven't found the PC address where
> its value is
> stored.

You can't , the PC isn't part of the io registers.
But you can do a call/rcall to a simple return and get it from the stack:

         IN    ZH,SPH
         IN    ZL,SPL                     
         SBIW  ZL,2       ;
         RCALL doRET      ; push low(adr); push high(adr)
adr:     LDD   R17,Z+1    ; get low(PC)
         LDD   R16,Z+2    ; get high(PC)

doRET:   RET


obviously you can do all the work at the doRET function without
clobbering the Z register:

         RCALL doRET      ; push low(adr); push high(adr)
adr:    

doRET:  
         POP   R17        ; pop the desired address, high byte first 
         POP   R16        ; low byte
         PUSH  R16
         PUSH  R17
         RET

all this is valid for devices with 16 bit pc at max.

regards
>
> I want to do this because my code is locking up somewhere and
> if I know the
> last
> PC address I can see the line of code it is doing this on.
>
> cheers,
> Jamie Morken
>
>
> avr-gcc-list at http://avr1.org
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]