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: 28 March 2012 19:17 To: AVR-Chat@yahoogroups.com Subject: [AVR-Chat] Re: Mixing C and assembly with special requirements. > --- In AVR-Chat@yahoogroups.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