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

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

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


From: Royce & Sharal Pereira
Subject: [avr-gcc-list] Fw: Can this be optimised?
Date: Wed, 28 Jul 2004 01:04:37 +0530

Hi, all,

Replying to my own mail...

----- Original Message ----- 
> 
> Can this be optimised somehow?
> The following code:-
> //------------------------------
> unsigned int tmp;
> //......etc
>  tmp= ADCL |(ADCH<<8);
> //------------------------------
> gets compiled(correctly) as:
>  
>  1376 04d0 84B1        in r24,36-0x20
>  1377 04d2 282F        mov r18,r24
>  1378 04d4 3327        clr r19
>  1379 04d6 85B1        in r24,37-0x20
>  1380 04d8 9927        clr r25
>  1381 04da 982F        mov r25,r24
>  1382 04dc 8827        clr r24
>  1383 04de 282B        or r18,r24
>  1384 04e0 392B        or r19,r25
>  1385 04e2 3093 0000   sts (tmp)+1,r19
>  1386 04e6 2093 0000   sts tmp,r18
> 
> Is there a way (without using assembly) to shorten this to:
> 
>               in     rxx,     36-0x20
>               sts   tmp,    rxx
>               in     ryy,     37-0x20
>               sts   tmp+1, ryy
> 
//-----------------------------------------------------
I got the answer:

unsigned int tmp;
unsigned char *ptr= &tmp;

*ptr++= ADCL;
*ptr= ADCH;
//-------------------------------------------------------

Thanks,
--Royce.


 



reply via email to

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