реклама на сайте
подробности

 
 
> WinAVR-20090313. Непонятная бага
_Pasha
сообщение Sep 30 2009, 16:05
Сообщение #1


;
******

Группа: Участник
Сообщений: 5 646
Регистрация: 1-08-07
Пользователь №: 29 509



Всем привет!
Исходничег:
Код
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;
}


Листинг вызова 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

А далее - все как должно быть

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(cool.gif;
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



Бага или нет?
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
_Pasha
сообщение Oct 6 2009, 12:01
Сообщение #2


;
******

Группа: Участник
Сообщений: 5 646
Регистрация: 1-08-07
Пользователь №: 29 509



CODE

#include <avr/io.h>
static struct Tpin_xrf
{
volatile void *port;
uint8_t mask;
} pin_xrf[5]={
{.port=&PORTB, .mask= 1},
{.port=&PORTB, .mask= 0x80},
{.port=&PORTB, .mask= 0x10},
{.port=&PORTB, .mask= 0x40},
{.port=&PORTB, .mask= 0x20},
};

int main(void)
{
for(uint8_t j=0;j<5;j++)
{
if(*((uint8_t*)pin_xrf[j].port) & pin_xrf[j].mask) PORTC |= 1; else PORTC &= ~1;
}
return 0;
}


CODE

int main(void)
{
5c: a0 e0 ldi r26, 0x00 ; 0
5e: b1 e0 ldi r27, 0x01 ; 1
for(uint8_t j=0;j<5;j++)
{
if(*((uint8_t*)pin_xrf[j].port) & pin_xrf[j].mask) PORTC |= 1; else PORTC &= ~1;
60: ed 91 ld r30, X+
62: fc 91 ld r31, X
64: 11 97 sbiw r26, 0x01 ; 1
66: 80 81 ld r24, Z
68: 12 96 adiw r26, 0x02 ; 2
6a: 9c 91 ld r25, X
6c: 12 97 sbiw r26, 0x02 ; 2
6e: 89 23 and r24, r25
70: 11 f0 breq .+4 ; 0x76 <main+0x1a>
72: 40 9a sbi 0x08, 0 ; 8
74: 01 c0 rjmp .+2 ; 0x78 <main+0x1c>
76: 40 98 cbi 0x08, 0 ; 8
78: 13 96 adiw r26, 0x03 ; 3
{.port=&PORTB, .mask= 0x20},
};

int main(void)
{
for(uint8_t j=0;j<5;j++)
7a: 81 e0 ldi r24, 0x01 ; 1
7c: af 30 cpi r26, 0x0F ; 15
7e: b8 07 cpc r27, r24
80: 79 f7 brne .-34 ; 0x60 <main+0x4>
{
if(*((uint8_t*)pin_xrf[j].port) & pin_xrf[j].mask) PORTC |= 1; else PORTC &= ~1;
}
return 0;
}
82: 80 e0 ldi r24, 0x00 ; 0
84: 90 e0 ldi r25, 0x00 ; 0
86: 08 95 ret



Что я хотел сказать: Доступ к полям структуры почему-то делается через Х а не через Z с использованием LDD/STD. Странноватое назначение регистровых пар. Можно ли как-то улучшить этот момент?
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 23rd July 2025 - 08:21
Рейтинг@Mail.ru


Страница сгенерированна за 0.01393 секунд с 7
ELECTRONIX ©2004-2016