Latency for servicing interrupts

Discussion of issues related specifically to writing code for native mode devices. This includes ZBasic code as well as assembly language code and C code, both inline and standalone.
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

It all depends where it is done.

They are the same if done in Main because the compiler can pre-compute the address of an array element because the address of the array is known at compile time.

If the array is a parameter to a function or subroutine then the compiler has to use "indexed" addressing where it loads (or saves) data based on an index from an address.

If you write the code using a variable for the index then this is also indexed addressing where the compiler has to first load the start address of the array and then "index" down to the specific element.
Mike Perks
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

Thanks Mike

So am i right in thinking then that

arrayvariable(1) is the same speed as a standard single var, but arrayvariable(variable) would be slightly slower?

Ben
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

sturgessb wrote: So am i right in thinking then that

arrayvariable(1) is the same speed as a standard single var, but arrayvariable(variable) would be slightly slower?
Yes assuming that arrayvariable is defined as global data outside of the ISR.

In terms of native code, indexed addressing usually generates one or two extra AVR machine instructions to setup the index register (usually Y or Z). - say 4 clock cycles.

If you asking about whether you should optimize the ISR by loop unrolling or some other method, I would suggest you measure the performance first and only optimize if necessary. If you plan to try optimizing this way I would go straight to AVR assembler language and enclose the code using #asm and #endasm.
Mike Perks
Post Reply