Yahoo Groups archive

AVR-Chat

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

Message

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

2012-03-29 by Steve Hodge

Thanks for the help, tips and pitfalls to watch for.  I've looked at the
links and I think I have it more or less figured out.   Steve

 

From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
Of Tim Mitchell
Sent: Thursday, March 29, 2012 1:29 AM
To: AVR-Chat@yahoogroups.com
Subject: RE: [AVR-Chat] Re: Mixing C and assembly with special requirements.

 

  

----Original Message----
From: AVR-Chat@yahoogroups.com <mailto:AVR-Chat%40yahoogroups.com> 
[mailto:AVR-Chat@yahoogroups.com <mailto:AVR-Chat%40yahoogroups.com> ] On
Behalf Of Don Kinzer
Sent: 28 March 2012 19:17 To: AVR-Chat@yahoogroups.com
<mailto:AVR-Chat%40yahoogroups.com> 
Subject: [AVR-Chat] Re: Mixing C and assembly with special
requirements. 

> --- In AVR-Chat@yahoogroups.com <mailto:AVR-Chat%40yahoogroups.com> ,
"Steve Hodge"
> <steve@...> wrote: 
> > what do you do to pass C arrays and C structs?
> The assembly knows nothing about C structures or even
> simple C types. Consequently, you have to write the code
> manually to index arrays and access structure elements. 
> I've posted a simple example available at the link below.
>

You can get into trouble quickly here as you have to know exactly how the
compiler has stored the structs in RAM. The map file can be very helpful in
working out what it has done. 

> If you're going to write C-callable subroutines in
> assembly language, you'll need to read the avr-libc FAQ
> entry describing which registers may be modified and
> which must be preserved. 
> 
> http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_reg_usage

That's a good page... it's (to my mind) slightly vague on how function
parameters are passed - if passing chars it uses r24, r22, r20 down to r8.
If passing 16 bit parameters it uses r25:r24 (r25 is high byte), r23:r22
etc. For 32 bit it uses r25:24:23:22
Obviously for asm interrupt routines you have to save and restore
everything.

-- 
Tim Mitchell





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

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.