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

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

Re: [avr-gcc-list] Can this be optimised?


From: Ned Konz
Subject: Re: [avr-gcc-list] Can this be optimised?
Date: Tue, 27 Jul 2004 13:42:47 -0700
User-agent: KMail/1.6.2

On Tuesday 27 July 2004 12:14 pm, Royce & Sharal Pereira wrote:

> Can this be optimised somehow?
> The following code:-
> //------------------------------
> unsigned int tmp;
> //......etc
>  tmp= ADCL |(ADCH<<8);
> //------------------------------

Just use the 16-bit version of the definition (assuming they're adjacent, 
which your example shows).

/*
avr-gcc -O3 -Wall -Wl,-Map,test.map -g -mtiny-stack -mint8 -mmcu=atmega16 -o 
test.elf test.c
avr-objdump -h -S  test.elf | tee test.lst
*/ 

#include <inttypes.h>
#include <io.h>
// which has something like:
// #define ADCW _SFR_IO16(0x04)

uint16_t tmp;
int main(void)
{
        tmp = ADCW;
        return 0;
}

produces exactly what you wanted:

        tmp = ADCW;
  96:   84 b1           in      r24, 0x04       ; 4
  98:   95 b1           in      r25, 0x05       ; 5
  9a:   90 93 61 00     sts     0x0061, r25
  9e:   80 93 60 00     sts     0x0060, r24


-- 
Ned Konz
http://bike-nomad.com



reply via email to

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