Sunday, May 9, 2010

Arduino disassembly

Moved the schedule around a bit. Today I am looking at AVR assembly to try to optimize my ISRs.

Just looking at the assembly listing was not very intuitive. The steps to follow:
  1. Hold shift while pressing the Arduino IDE compile button. This puts it into verbose mode.
  2. Take note of the temp directory it's performing your build in
  3. From the command prompt, "D:\Programs\arduino-0018\hardware\tools\avr\bin\avr-objdump -S HeliSAS.cpp.elf >> disassembly.txt"
Am looking at it now; there's a lot of optimization going on; fortunately my ISRs are short enough as it is, so maybe I can wrap my head around it and see if there's any improvement to be had.

Also, 0x3f is the SREG. Confused the hell out of me at first...

Update: My SPI ISR is 53 clocks = 6.6us (not counting jump/reti): 35 for context saving, 6 to check for queue buffer overflow, and 12 for the actual operation. I could cut out 8 clocks (1 us) in context saving by rewriting the Queue::push() routine in assembly (reduce the number of registers that get trashed), and there's another 9 clocks if I write the entire ISR in assembly (gcc pushes/pops some registers that don't change in the ISR), though that gets into modifying Queue's private members. Oh...that reminds me; Queue is a template class...so there's no way to do this without it being a hack.

On the other hand, 6.6 us is only 0.7% of the servo pulse full range (1-2 ms), so maybe we can just live with that.

No comments:

Post a Comment