[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Can this be optimised?
From: |
Theodore A. Roth |
Subject: |
Re: [avr-gcc-list] Can this be optimised? |
Date: |
Tue, 27 Jul 2004 12:42:17 -0700 (PDT) |
On Wed, 28 Jul 2004, Royce & Sharal Pereira wrote:
> Hi, all,
>
> 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
>
> Or is in-line assembly the best way?
Sure. Do it like this:
int main (void)
{
volatile uint16_t foo;
foo = ADC;
return (int)foo;
}
Compiling with -Os yields this asm code:
int main (void)
{
da: cd ef ldi r28, 0xFD ; 253
dc: d0 e1 ldi r29, 0x10 ; 16
de: de bf out 0x3e, r29 ; 62
e0: cd bf out 0x3d, r28 ; 61
volatile uint16_t foo;
foo = ADC;
e2: 84 b1 in r24, 0x04 ; 4
e4: 95 b1 in r25, 0x05 ; 5
e6: 89 83 std Y+1, r24 ; 0x01
e8: 9a 83 std Y+2, r25 ; 0x02
return (int)foo;
ea: 89 81 ldd r24, Y+1 ; 0x01
ec: 9a 81 ldd r25, Y+2 ; 0x02
ee: 0c 94 79 00 jmp 0xf2
---
Ted Roth
PGP Key ID: 0x18F846E9
Jabber ID: address@hidden