Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Getting The Program Counter in C

2005-12-04 by Dave Hylands

HI,

On 12/4/05, Larry Barello <yahoo@barello.net> wrote:
> The only way to get the PC is to interrupt the processor.  The PC will be on
> the stack upon entry into the ISR.  WDT will reset the processor and you
> will lose your PC.

Every time you call a subroutine, the PC is pushed onto the stack.
Therefore you should be able to write a simple assembler function like
this:

GetPC:
    pop r24
    pop r25
    push r25
    push r24
    ret

I haven't tested the above, bbut I think that I got the order right
r24=LSB, r25=MSB

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.