Assembly Interupt Service Routine

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will not bore you with the trouble I was having with IAR. It is a lot harder than you would think to convert a complex project to a different compiler, but I decided to bite the bullet and convert to GCC. Three hours later, I am still struggling.

The project has several c files and a file for each interrupt service routine, written in assembler.

Here is an example of an ISR:

#include
#include
.ORG TIMER1_OVF_vect
rjmp Timer1 ; Timer 1 overflow
.CSEG
Timer1:
EXTERN Option, Tilt, Analog, Tilt_state
push r16
in r16,SREG
push r16

The EXTERN statement generates an error. These variables are allocated in C and are used to pass data between the ISR and C. What am I doing wrong?

in r16,SREG generates a "must be less than 64" error. A similar error is generated for things like PINC or any I/O reference. What can I do?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you see the example in the GCC user manual:

http://www.nongnu.org/avr-libc/u...

That shows ISRs being implemented in Asm but sharing data with C code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The avr-as directives should be .extern and .global
Note the periods.

You will take a lot longer than three hours to port code if you do not read the documentation.

The example code is very useful too.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, I did not see that. Thanks. I now have:

#include
#include
.extern Option, Tilt, Analog, Tilt_state
.global TIM1_OVF_vect
TIM1_OVF_vect:
push r16
in r16,SREG
push r16

I guess gcc generates the rjmp in the interupt table.

But I still have the problem with in r16,SREG "number must be positive and less than 64". The include statements do not generate an error and AVR STudio inserts the "-mmcu=atmega8". And that works with C.

What could it be?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From the demo Cliff pointed to:

	in	sreg_save, _SFR_IO_ADDR(SREG)

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now I see it!
It should be
in r16,_SFR_IO_ADDR(SREG)

Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you post every single problem it will save you having to read the avr-gcc docs.

You should be able to succeed within a few weeks or days. On the other hand a bit of judicious study will answer your questions within the hour.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You probably want to also read these pages in the manual if you haven't already:

http://www.nongnu.org/avr-libc/u...
http://www.nongnu.org/avr-libc/u...