Assembly delay function: GCC vs ICCAVR

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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
#define XTAL 14745000

delay for a minimum of <us> microseconds
the number of loops is calculated at compile-time from MCU clock
#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
        __asm__ __volatile__ (
        "1: sbiw %0,1" "\n\t"
        "brne 1b"                              // 4 cycles/loop
        : "=w" (__count)
        : "0" (__count)

Re: Assembly delay function: GCC vs ICCAVR
Quoted text here. Click to load it

The code generates either:

        rjmp label

if incoming __count parameter is == 0,


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.



Tauno Voipio
tauno voipio (at) iki fi

Site Timeline