Equivalent of millis() in Atmel studio This code It works in atmel studio.But this millis function is starting to run 31-34 miliseconds behind of arduino millis fuction.Why?I am adding picture.

Picture: https://imageshack.com/a/img922/3060/umtNJp.jpg

Update 2

#define F_CPU 8000000UL
#include &lt;avr/io.h&gt;

#include &lt;avr/interrupt.h&gt;

#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256))
#define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000)
// the fractional number of milliseconds per timer0 overflow. we shift right
// by three to fit these numbers into a byte. (for the clock speeds we care
// about - 8 and 16 MHz - this doesn't lose precision.)
#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) &gt;&gt; 3)
#define FRACT_MAX (1000 &gt;&gt; 3)
volatile unsigned long timer0_overflow_count = 0;
volatile unsigned long timer0_millis = 0;
static unsigned char timer0_fract = 0;

volatile uint8_t count;

ISR (TIMER0_OVF_vect)

{


    unsigned long m = timer0_millis;
    unsigned char f = timer0_fract;

    m += MILLIS_INC;
    f += FRACT_INC;
    if (f &gt;= FRACT_MAX) {
        f -= FRACT_MAX;
        m += 1;
    }

    timer0_fract = f;
    timer0_millis = m;
    timer0_overflow_count++;





}

unsigned long millis()
{
    unsigned long m;
    uint8_t oldSREG = SREG;

    // disable interrupts while we read timer0_millis or we might get an
    // inconsistent value (e.g. in the middle of a write to timer0_millis)
    cli();
    m = timer0_millis;
    SREG = oldSREG;

    return m;
}



int main (void)

{
    DDRB |= (1&lt;&lt;0); 
    TCNT0 = 0;
    count = 0;
    TCCR0B |= (0&lt;&lt;CS02) | (1&lt;&lt;CS01) | (1&lt;&lt;CS00); // PRESCALER 64
    TIMSK0 = (1&lt;&lt;TOIE0);
    sei();

    while(1)  
    {
        millis() to uart.

    }

}
The millis() function is defined in the Arduino Core for AVR architecture, specifically the wiring.c file.

You can see that timer0 is setup with various parameters for prescaling and interrupt triggering and handling of timer0 overflow such that a variable called timer0_millis contains the number of milliseconds since the sketch started. 

The millis() function basically returns that timer0_millis value.

If you wish to make use of the function in AVR Studio, then you would need to include the same kind of timer0 setup and interrupt/overflow handling that the Arduino core does.