[Top][All Lists]

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

Re: [avr-gcc-list] assembly-c mix and interrupts

From: Julius Luukko
Subject: Re: [avr-gcc-list] assembly-c mix and interrupts
Date: Fri, 20 Nov 2009 11:41:58 +0200
User-agent: KMail/1.11.2 (Linux/2.6.28-16-generic; KDE/4.2.2; x86_64; ; )

(note to the list: Alexander replied me off-list but I am replying to the list 

On Thursday 19 November 2009, you wrote:
> Thanks for your reply,
> I understand that it is VERY important to store/restore the SREG in an
> interrupt function. Can you please confirm for me that the ISR() c macro
> does this for me and also, does your advice extend to functions outside the
> interrupt routine? I have found reference material stating which registers
> should be stored, but none of them mention the SREG in any way.

I can't provide you with a reference but AFAIK this is done on the gcc level 
(which I know nothing about). The actual definition in the avr-libc source 
does not show it:


Anyway, SREG should always be stored to the stack when using the ISR() macro. 
Maybe someone can provide with a reference to prove this.

An excerpt from a C generated ISR () shows an example (I don't remember which 
version of gcc or avr-libc was used, this was just easily found):

00000108 <__vector_18>:
 108:   1f 92           push    r1
 10a:   0f 92           push    r0
 10c:   0f b6           in      r0, 0x3f        ; 63
 10e:   0f 92           push    r0
 110:   11 24           eor     r1, r1
 112:   8f 93           push    r24
 114:   9f 93           push    r25
 116:   ef 93           push    r30
 118:   ff 93           push    r31

SREG is memory mapped to 0x3f. As you can see, you can't push SREG directly, 
you must use a register for that and therefore you must push the register 

One thing to note also in the excerpt is the clearing of r1 (eor r1, r1). If 
you intend to call C functions from your assembly ISR, you must do this also. 
This might provide you with some more information



> > From: address@hidden
> > To: address@hidden
> > Subject: Re: [avr-gcc-list] assembly-c mix and interrupts
> > Date: Thu, 19 Nov 2009 15:34:16 +0200
> > CC: address@hidden
> >
> > On Thursday 19 November 2009, darkschine wrote:
> > > Before I continue, I would like to suggest a resolution to my problem.
> > > I am using the ATmega328P
> > > My assembly code follows a standard that ALL registers used are pushed
> > > and popped from the stack. However, my assembly code does NOT store the
> > > SREG. Could this be causing my problems?
> >
> > You can do next to nothing without modifying the SREG. Why don't you add
> > pushing the SREG also to the stack. I wouldn't dare to not to save it.
> >
> > --
> > Julius
> _________________________________________________________________
> Looking for a date? View photos of singles in your area!
> http://clk.atdmt.com/NMN/go/150855801/direct/01/

D.Sc. Julius Luukko
Laboratory of Control Engineering and Digital Systems
Lappeenranta University of Technology, FINLAND
phone:+358-5-621 6713, fax:+358-5-621 6799, www: http://www.ee.lut.fi

reply via email to

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