Jon Lochner - 2006-12-16

Hey all,

I tried adding PORTA and PORTB bitfield definitions to the header and library files for the pic16f88 like someone had for the '84 but sdcc generates odd asm as a result.  The code works as intended but it is ugly.  Any suggestions??

For example:

;       .line   43; "monitor.c" RA0++;
        BANKSEL r0x1003
        CLRF    r0x1003
        BANKSEL _PORTA_bits
        BTFSS   _PORTA_bits,0
        GOTO    _00004_DS_
        BANKSEL r0x1003
        INCF    r0x1003,F
        BANKSEL r0x1003
        INCF    r0x1003,F
        RRF     r0x1003,W
        BTFSC   STATUS,0
        GOTO    _00005_DS_
        BANKSEL _PORTA_bits
        BCF     _PORTA_bits,0
        BTFSS   STATUS,0
        GOTO    _00006_DS_
        BANKSEL _PORTA_bits
        BSF     _PORTA_bits,0

PORTB ^= 0x01;
;       .line   42; "monitor.c" PORTB ^= 0x01;
        MOVLW   0x01
        XORWF   _PORTB,F

The lines I added are:
volatile __PORTA_bits_t      __at(PORTA_ADDR)      PORTA_bits;
volatile __PORTB_bits_t      __at(PORTB_ADDR)      PORTB_bits;

// ----- PORTA bits --------------------
typedef union {
    struct {
    unsigned char RA0:1;
    unsigned char RA1:1;
    unsigned char RA2:1;
    unsigned char RA3:1;
    unsigned char RA4:1;
    unsigned char RA5:1;
    unsigned char RA6:1;
    unsigned char RA7:1;
} __PORTA_bits_t;
extern volatile __PORTA_bits_t __at(PORTA_ADDR) PORTA_bits;

#define RA0             PORTA_bits.RA0
#define RA1             PORTA_bits.RA1
#define RA2             PORTA_bits.RA2
#define RA3             PORTA_bits.RA3
#define RA4             PORTA_bits.RA4
#define RA5             PORTA_bits.RA5
#define RA6             PORTA_bits.RA6
#define RA7             PORTA_bits.RA7

// ----- PORTB bits --------------------

typedef union {
    struct {
    unsigned char RB0:1;
    unsigned char RB1:1;
    unsigned char RB2:1;
    unsigned char RB3:1;
    unsigned char RB4:1;
    unsigned char RB5:1;
    unsigned char RB6:1;
    unsigned char RB7:1;
} __PORTB_bits_t;
extern volatile __PORTB_bits_t __at(PORTB_ADDR) PORTB_bits;

#define RB0             PORTB_bits.RB0
#define RB1             PORTB_bits.RB1
#define RB2             PORTB_bits.RB2
#define RB3             PORTB_bits.RB3
#define RB4             PORTB_bits.RB4
#define RB5             PORTB_bits.RB5
#define RB6             PORTB_bits.RB6
#define RB7             PORTB_bits.RB7