I've been looking at the code generated by avr-gcc 3.4.5, and
it sure looks like there's a lot of extra overhead involved in
ISRs. Let's write an ISR that just toggles a port pin every
time the interrupt happens. On the MSP430 using gcc 3.3,
here's what you do:
interrupt(PORT1_VECTOR) edgeHandler(void)
{
P6OUT ^= 0x0001;
}
That generates 3 words of code (2 instructions including the reti):
92:modem.c **** interrupt(PORT1_VECTOR) edgeHandler(void)
93:modem.c **** {
199 .LM16:
200 /* prologue: frame size = 0 */
201 .L__FrameSize_edgeHandler=0x0
202 .L__FrameOffset_edgeHandler=0x0
203 /* prologue end (size=0) */
94:modem.c **** P6OUT ^= 0x01;
205 .LM17:
206 004e D2E3 3500 xor.b #llo(1), &0x0035
95:modem.c **** }
208 .LM18:
209 0052 0013 reti
210 /* epilogue: not required */
211 /* function edgeHandler size 3 (2) */
No surprises there, pretty much what one would expect.
Here's the same thing on an AVR (using avr-libc's ISR() macro):
ISR(INT0_vect)
{
PORTA ^= 0x01;
}
Holy bloat! That generates _18_words_ of code. I can see why
r24 and r25 are pushed and restored, but what's all the rest of
that stuff for? At first glance I thought the AVR was a
half-way decent architecture, but the more I work with it the
more I'm convinced it's a seriously broken architecture. Am I
doing something wrong that's causing gcc to generate all that
apparently useless prolog/epilog code? Or am I just too dumb
to understand why it is needed?
83:modem.c **** ISR(INT0_vect)
84:modem.c **** {
236 .LM25:
237 /* prologue: frame size=0 */
238 006c 1F92 push __zero_reg__
239 006e 0F92 push __tmp_reg__
240 0070 0FB6 in __tmp_reg__,__SREG__
241 0072 0F92 push __tmp_reg__
242 0074 1124 clr __zero_reg__
243 0076 8F93 push r24
244 0078 9F93 push r25
245 /* prologue end (size=7) */
85:modem.c **** PORTA ^= 0x01;
247 .LM26:
248 007a 8BB3 in r24,59-0x20
249 007c 91E0 ldi r25,lo8(1)
250 007e 8927 eor r24,r25
251 0080 8BBB out 59-0x20,r24
252 /* epilogue: frame size=0 */
253 0082 9F91 pop r25
254 0084 8F91 pop r24
255 0086 0F90 pop __tmp_reg__
256 0088 0FBE out __SREG__,__tmp_reg__
257 008a 0F90 pop __tmp_reg__
258 008c 1F90 pop __zero_reg__
259 008e 1895 reti
260 /* epilogue end (size=7) */
261 /* function __vector_1 size 18 (4) */
86:modem.c **** }
--
Grant Edwards grante Yow! ALFRED JARRY! Say
at something about th' DEATH
visi.com of DISCO!!