avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] A Question Of Optmization


From: Karl O. Feger
Subject: [avr-gcc-list] A Question Of Optmization
Date: Tue, 15 Apr 2008 20:12:01 +0200

Dear all,

I'm relatively new to AVR-GCC and try to do something,

that is standing procedure in C51 for me. I want to

program a delay based on a timer-ISR. The code looks

like this:

*********************************

//isr-test, very basic

// cpu: ATMega128

// speed: 16 mhz

 

 

#include <avr/io.h>

#include <avr/interrupt.h>

 

 

unsigned char TimerTick;

 

 

//---------------------------------------

// Timer/Counter1 Compare Match A

//---------------------------------------

 

ISR(TIMER1_COMPA_vect) // timer_compare_a

{

 

        TimerTick ? TimerTick-- : 0;

}

 

//---------------------------------------

// main

//---------------------------------------

 

int main()

{

 

 

        unsigned char a;

 

        // --- TIMER1_COMPA irq ---

        // selected time = 10 ms (160000 ticks)

        // prescaler = 8 (8 ticks ... 32.768 ms)

        TCCR1B = (1<<WGM12)|(1<<CS11);

        OCR1AH = 0x4e;

        OCR1AL = 0x20;

        TIMSK |= (1<<OCIE1A);

 

        // main loop

        sei();

 

        for (;;)

        {

        TimerTick = 10;

        while(TimerTick);

        a = ~a;

        }

        return(0);

}

********************************

 

When I compile this without optimization (-O0)

Everything is just fine and as expected. When I select

ANY other optimization level, the resulting assembler

code looks like this (starting at "TimerTick = 10;"):

**********************

45:            TimerTick = 10;

+00000086:   E08A        LDI     R24,0x0A         Load

immediate

+00000087:   93800100    STS     0x0100,R24     

Store direct to data space

+00000089:   CFFF        RJMP    PC-0x0000      

Relative jump

***********************

so the program stops here and loops.

 

Where is my thinking wrong? I tried all sources I could

imaging.

 

Thanks for any help

Karl

 

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]