Исходничег:
Код
int main(void) __attribute__ ((OS_main));
static inline uint8_t bit_swp(const uint8_t reg)__attribute__ ((always_inline));
volatile uint8_t a;
int main(void)
{
uint8_t b = a;
b = bit_swp(b);
a=b;
return 0;
}
uint8_t bit_swp(const uint8_t reg)
{
uint8_t www=0;
if(reg & 0x80) www |= 0x20;
if(reg & 0x40) www |= 0x80;
if(reg & 0x20) www |= 0x02;
if(reg & 0x10) www |= 0x01;
return www;
}
static inline uint8_t bit_swp(const uint8_t reg)__attribute__ ((always_inline));
volatile uint8_t a;
int main(void)
{
uint8_t b = a;
b = bit_swp(b);
a=b;
return 0;
}
uint8_t bit_swp(const uint8_t reg)
{
uint8_t www=0;
if(reg & 0x80) www |= 0x20;
if(reg & 0x40) www |= 0x80;
if(reg & 0x20) www |= 0x02;
if(reg & 0x10) www |= 0x01;
return www;
}
Листинг вызова bit_swp() начинается с непонятного действия
Код
86: 28 2f mov r18, r24
88: 22 1f adc r18, r18
8a: 22 27 eor r18, r18
8c: 22 1f adc r18, r18
8e: 22 95 swap r18
90: 22 0f add r18, r18
92: 20 7e andi r18, 0xE0; 224
88: 22 1f adc r18, r18
8a: 22 27 eor r18, r18
8c: 22 1f adc r18, r18
8e: 22 95 swap r18
90: 22 0f add r18, r18
92: 20 7e andi r18, 0xE0; 224
А далее - все как должно быть
CODE
if(reg & 0x40) www |= 0x80;
94: 86 fd sbrc r24, 6
96: 20 68 ori r18, 0x80 ; 128
if(reg & 0x20) www |= 0x02;
98: 85 fd sbrc r24, 5
9a: 22 60 ori r18, 0x02 ; 2
if(reg & 0x10) www |= 0x01;
9c: 84 fd sbrc r24, 4
9e: 21 60 ori r18, 0x01 ; 1
int main(void)
{
uint8_t b = a;
b = bit_swp(

a=b;
a0: 20 93 02 01 sts 0x0102, r18
return 0;
}
a4: 80 e0 ldi r24, 0x00 ; 0
a6: 90 e0 ldi r25, 0x00 ; 0
a8: 08 95 ret
-------- begin --------
avr-gcc (WinAVR 20090313) 4.3.2
Copyright © 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Compiling C: test.c
C:/WinAVR-20090313/bin/avr-gcc -c -mmcu=atmega48 -I. -gdwarf-2 -DF_CPU=8000000UL
-Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wst
rict-prototypes -Wa,-adhlns=./test.lst -std=gnu99 -fno-split-wide-types -mcall-
prologues --param inline-call-cost=3 -fno-unroll-loops -MMD -MP -MF .dep/test.o.
d test.c -o test.o
Linking: test.elf
C:/WinAVR-20090313/bin/avr-gcc -mmcu=atmega48 -I. -gdwarf-2 -DF_CPU=8000000UL -O
s -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstric
t-prototypes -Wa,-adhlns=test.o -std=gnu99 -fno-split-wide-types -mcall-prologu
es --param inline-call-cost=3 -fno-unroll-loops -MMD -MP -MF .dep/test.elf.d tes
t.o led7s.o --output test.elf -Wl,-Map=test.map,--cref -lm
Creating load file for Flash: test.hex
C:/WinAVR-20090313/bin/avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock test.elf
test.hex
Бага или нет?