Hello,
when compiling the following code I get not optimal code:
--------------------------------------
#include <avr/io.h>
int
main(void)
{
volatile uint8_t foo=3;
uint16_t bar;
bar = (uint8_t)(64+foo)<<8; // *
return bar;
}
--------------------------------------
As you can see, I want to set the upper byte of bar using foo which
can change before the line in question (marked with a *).
Compiling with
avr-gcc main.c -mmcu=atmega162 -Wa,-adhlns=main.lst -Os
yields following asm code:
20 0008 83E0 ldi r24,lo8(3)
21 000a 8983 std Y+1,r24
22 000c 8981 ldd r24,Y+1
23 000e 805C subi r24,lo8(-(64))
24 0010 9927 clr r25
25 0012 982F mov r25,r24
26 0014 8827 clr r24
Why is r25 cleared just before moving r24 to r25 and is there a way to
change my example code in a way that avr-gcc will not produce
redundant code?
Another question:
When accessing (uint8_t)(variable>>8) avr-gcc produces
420 018e 8091 0000 lds r24,variable
421 0192 9091 0000 lds r25,(variable)+1
422 0196 892F mov r24,r25
423 0198 9927 clr r25
which could also be written as
lds r24,(variable)+1
clr r25
Is there a way to force this code without using inline asm?