Yahoo Groups archive

AVR-Chat

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

Thread

Re: Mixing C and assembly with special requirements.

Re: Mixing C and assembly with special requirements.

2012-03-29 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "Tim Mitchell" <tim@...> wrote:
> And remember to save SREG in interrupt routines.
Unless, of course, it isn't modified.  Although usually not the case, it is possible to construct an ISR that does not modify SREG.  Take, for example, this one that toggles an output on each external interrupt (assuming A.7 is set to be an output and that the device supports port bit toggling by writing to the PINx register).

.global INT0_vect
INT0_vect:
  push r24
  ldi r24, 0x80
  out _SFR_IO_ADDR(PINA), r24
  pop r24
  reti

Another caveat for ISRs is that you *cannot* rely on r1 being zero in an ISR as you can in a "normal" routine.  Moreover, if you call any C functions from an ISR (usually not recommended) you must set r1 to zero before calling any C function.

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

RE: [AVR-Chat] Re: Mixing C and assembly with special requirements.

2012-03-29 by Tim Mitchell

----Original Message----
Show quoted textHide quoted text
From: AVR-Chat@yahoogroups.com
[mailto:AVR-Chat@yahoogroups.com] On Behalf Of Don Kinzer
Sent: 29 March 2012 16:05 To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] Re: Mixing C and assembly with special
requirements. 

> --- In AVR-Chat@yahoogroups.com, "Tim Mitchell" <tim@...>
> wrote: 
> > Obviously for asm interrupt routines you have to save
> > and restore everything.
> To be more precise, you need only save/restore the
> registers modified in the ISR (and any functions it
> calls).  
> 

Indeed, I was a bit unclear there, I meant that you can't even modify the "clobberable" registers.

Need to watch out for stuff like R0/R1 being modified when you use the mul instruction. Got bitten by that once. And remember to save SREG in interrupt routines.


-- 
Tim Mitchell

Re: [AVR-Chat] Re: Mixing C and assembly with special requirements.

2012-03-29 by wagnerj@proaxis.com

> --- In AVR-Chat@yahoogroups.com, "Tim Mitchell" <tim@...> wrote:
>> And remember to save SREG in interrupt routines.
> Unless, of course, it isn't modified.  Although usually not the case, it
> is possible to construct an ISR that does not modify SREG.  Take, for
> example, this one that toggles an output on each external interrupt
> (assuming A.7 is set to be an output and that the device supports port bit
> toggling by writing to the PINx register).
>
> .global INT0_vect
> INT0_vect:
>   push r24
>   ldi r24, 0x80
>   out _SFR_IO_ADDR(PINA), r24
>   pop r24
>   reti
>
> Another caveat for ISRs is that you *cannot* rely on r1 being zero in an
> ISR as you can in a "normal" routine.  Moreover, if you call any C
> functions from an ISR (usually not recommended) you must set r1 to zero
> before calling any C function.
>
> Don Kinzer
> ZBasic Microcontrollers
> http://www.zbasic.net
>

Very informative thread! Much appreciated...

Jim Wagner
Oregon Research Electronics

RE: [AVR-Chat] Re: Mixing C and assembly with special requirements.

2012-03-29 by Steve Hodge

+1, Steve
Show quoted textHide quoted text
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
Of wagnerj@proaxis.com
Sent: Thursday, March 29, 2012 9:24 AM
To: AVR-Chat@yahoogroups.com
Subject: Re: [AVR-Chat] Re: Mixing C and assembly with special requirements.


Very informative thread! Much appreciated...

Jim Wagner
Oregon Research Electronics





[Non-text portions of this message have been removed]

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.