2

Following on from my other question, Help optimising this C (AVR) code? :), I just realised that I don't really know the mechanics of how to implement an ISR in assembly within my C program. I googled, but I didn't find anything too useful.

Basically I want to set up everything else in my C project (including the registers to get the interrupt to fire), but I want the interrupt to execute some assembly code that I've written.

I'm using AVR studio 6 on Windows if that helps. I've been told I need to use .s files but apart from that I'm not really sure what to do. Is the basic structure just the following?

#include <avr\io.h> 
TIMER1_COMPA_vect:
    ; assembly instructions here

If I want the assembly to run when the TIMER1_COMPA_vect interrupt is fired (this is the name of the ISR in C). Or am I totally off track? What is a basic template of what I need to do? Or if it's a dumb question, is there a link where I can find more information?

Community
  • 1
  • 1
JimR
  • 2,145
  • 8
  • 28
  • 37
  • For some reason I can't seem to answer my own question but I think I found what I was after: http://www.nongnu.org/avr-libc/user-manual/group__asmdemo.html – JimR Apr 16 '11 at 01:54

1 Answers1

1

The Art of Assembly Language (by Randall Hyde) has two chapters about ISRs (17th and 18th, specifically sections 18.5 and 18.6 might help you). Shortly:

  1. Go to the IVT (interrupt vector table) and modify it with your ISR segment and offset, saving the old values
  2. You should do a TSR (terminate and stay resident) program, so that your ISR stays resident into memory even when the user closes the window
  3. Remember to call the old ISR after you're done with the work (this is called interrupt chaining)
  4. your ISR should be re-entrant (so that if the interrupt is fired again when your ISR is still running the pc won't explode ;) )

By the way, you can obtain a pdf copy of that great book here

BlackBear
  • 22,411
  • 10
  • 48
  • 86