Assembly delay function: GCC vs ICCAVR

I need to port a function, which uses inline assembly in a way understood by gcc, to the compiler used in ImageCraft 's IDE ( ICC ). Because of the different calling convention for inline assembly I need to understand exactly what this lines of assembly code do, so I can rewrite it in a way ICCAVR understands it. Can someone, with knowledge of assembly, please support me to fulfil this task?

Thanks you.

XTAL is the clock frequency the Atmel uses. In my project it is 14 Mhz. #define XTAL 14745000

/************************************************************************* delay for a minimum of microseconds the number of loops is calculated at compile-time from MCU clock frequency

*************************************************************************/ #define delay(us) _delayFourCycles( ( ( 1*(XTAL/4000) )*us)/1000 ) /************************************************************************* delay loop for small accurate delays: 16-bit counter, 4 cycles/loop *************************************************************************/ static inline void _delayFourCycles(unsigned int __count) { if ( __count == 0 ) __asm__ __volatile__( "rjmp 1f\n 1:" ); // 2 cycles else __asm__ __volatile__ ( "1: sbiw %0,1" "\n\t" "brne 1b" // 4 cycles/loop : "=w" (__count) : "0" (__count) ); }
Reply to
FilterPunk
Loading thread data ...

The code generates either:

rjmp label label:

if incoming __count parameter is == 0,

otherwise:

label: sbiw reg,1 brne label

where reg is a register pair suitable for sbiw.

The __volatile__ attribute prevents the compiler from optimizing away the seemingly useless code.

HTH

--

Tauno Voipio
tauno voipio (at) iki fi
Reply to
Tauno Voipio

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.