-2

I want to make a code about accurate delay library in ATmega8 with winAVR as the compiler, do you have any idea to convert the code below to assembly? I have no idea to convert the code, because I don't understand assembly.

this is the code.

static __inline__ void __variable_delay_cycles(unsigned long __count)
{
    if (__count>65535)
    {
        __count=(__count-13)/6;
        DelayCyclesUL(__count);
    }
    else
    {
        if (!__count)
            return;
        if (__count<10)
            __count=1;
        else 
            __count=(__count-6)/4;
        DelayCyclesUI(__count);
    }
}

DelayCyclesUI and DelayCyclesUL are written in assembly code. Thanks.

Clifford
  • 88,407
  • 13
  • 85
  • 165
user3625159
  • 1
  • 1
  • 1
  • Have you tried compiling it to assembly for an atmega8? – EWit May 11 '14 at 10:12
  • 1
    Converting high level code to assembly is what compilers normally do. You would need a C compiler for the atmega8 platform. – n. m. could be an AI May 11 '14 at 10:20
  • 1
    StackOverflow is not a place for tutorials or step-by-step guides. Either use a C compiler as suggested earlier, or download the available documentation for your target CPU and start translating it yourself. If there's a specific part of the translation that's unclear, then you can ask a question about _that_ (describe exactly what you're doing and what the problem is). – Michael May 11 '14 at 10:25
  • As I understand it, converting this to assembly does not serve the purpose of SO: even if someone does so, the OP will *still* not understand the answer, by his own admission. – Jongware May 11 '14 at 11:46
  • What are you trying to achieve? – Clifford May 11 '14 at 11:48
  • why do you use `__` prefix for all identifiers? – phuclv May 11 '14 at 13:49

2 Answers2

0

Compile your code into an executable and debug it in avr-studio. Switch to the assembly view, you'll be able to copy&paste the compiled code from either into your own asm file. Depending on the length of delay you are after you might be better of considering using one of the hardware timers.

Anonymouse
  • 935
  • 9
  • 20
0

The compiler already translates the code to machine level instructions. It the -S compiler option will output the generated code in assembler form too.

However, the ATmega8 has three hardware timers that can produce cycle accurate timing independent of the code and any variability in the compilers translation with different options. You should use a hardware timer rather than "instruction loops" to implement delays.

Community
  • 1
  • 1
Clifford
  • 88,407
  • 13
  • 85
  • 165