#378 improvement of the bit-wise access

open
nobody
5
2012-09-12
2012-09-12
vloki
No

Disappointed by the new MCHP XC8 compiler in free version I just started to play with SDCC
I noticed that bit access may result in rather strange assembly code.

Here are three different C-code versions that all do the same thing. The aim is to modify one bit in
reference to another one:
LATBbits.LATB5 = PORTBbits.RB2;
---------------------------------------------------------------------
if(BTN_1 == BTN_ACTIVATED) // same as above
LED_4 = LED_ON;
else
LED_4 = !LED_ON;
---------------------------------------------------------------------
if(BTN_1 == BTN_ACTIVATED) // same as above
LED_4 = LED_ON;
if(BTN_1 != BTN_ACTIVATED)
LED_4 = !LED_ON;

The compiler creates the following assembly code:
279: ; .line 48; Quick_main_22a.c LATBbits.LATB5 = PORTBbits.RB2;
00A0 6A00 CLRF 0x0, ACCESS 280: CLRF r0x00
00A2 B481 BTFSC PORTB, 2, ACCESS 281: BTFSC _PORTBbits, 2
00A4 2A00 INCF 0x0, F, ACCESS 282: INCF r0x00, F
00A6 5000 MOVF 0x0, W, ACCESS 283: MOVF r0x00, W
00A8 0B01 ANDLW 0x1 284: ANDLW 0x01
00AA 38E8 SWAPF WREG, W, ACCESS 285: SWAPF WREG, W
00AC 44E8 RLNCF WREG, W, ACCESS 286: RLNCF WREG, W
00AE 6EF4 MOVWF PRODH, ACCESS 287: MOVWF PRODH
00B0 508A MOVF LATB, W, ACCESS 288: MOVF _LATBbits, W
00B2 0BDF ANDLW 0xDF 289: ANDLW 0xdf
00B4 10F4 IORWF PRODH, W, ACCESS 290: IORWF PRODH, W
00B6 6E8A MOVWF LATB, ACCESS 291: MOVWF _LATBbits
------------------------------------------------------------------------------------------------------------------------------------------
292: ; .line 50; Quick_main_22a.c if(BTN_1 == BTN_ACTIVATED) // same as above
00B8 B481 BTFSC PORTB, 2, ACCESS 293: BTFSC _PORTBbits, 2
00BA D002 BRA 0xC0 294: BRA _00106_DS_
295: ; .line 51; Quick_main_22a.c LED_4 = LED_ON;
00BC 9A8A BCF LATB, 5, ACCESS 296: BCF _LATBbits, 5
00BE D001 BRA 0xC2 297: BRA _00107_DS_
298: _00106_DS_:
299: ; .line 53; Quick_main_22a.c LED_4 = !LED_ON;
00C0 8A8A BSF LATB, 5, ACCESS 300: BSF _LATBbits, 5
301: _00107_DS_:
------------------------------------------------------------------------------------------------------------------------------------------
302: ; .line 55; Quick_main_22a.c if(BTN_1 == BTN_ACTIVATED) // same as above
00C2 B481 BTFSC PORTB, 2, ACCESS 303: BTFSC _PORTBbits, 2
00C4 D001 BRA 0xC8 304: BRA _00109_DS_
305: ; .line 56; Quick_main_22a.c LED_4 = LED_ON;
00C6 9A8A BCF LATB, 5, ACCESS 306: BCF _LATBbits, 5
307: _00109_DS_:
308: ; .line 57; Quick_main_22a.c if(BTN_1 != BTN_ACTIVATED)
00C8 A481 BTFSS PORTB, 2, ACCESS 309: BTFSS _PORTBbits, 2
00CA D7EA BRA 0xA0 310: BRA _00113_DS_
311: ; .line 58; Quick_main_22a.c LED_4 = !LED_ON;
00CC 8A8A BSF LATB, 5, ACCESS 312: BSF _LATBbits, 5

The first version looks the most easy but results in desaster ;-)
I would love to see:
LATBbits.LATB5 = PORTBbits.RB2;
BTFSC PORTB, 2, ACCESS
BSF LATB, 5, ACCESS
BTFSS PORTB, 2, ACCESS
BCF LATB, 5, ACCESS

Does someone know where to look in the SDCC source ???

Discussion

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks