Hello all,

 

I tried accessing an xdata location on an EZ-USB AN2131 two different ways, as an unsigned char and as a bit field structure. Here are the declarations:

 

struct bitsUSBCS

{

            unsigned SIGRSUME : 1; // bit 0

            unsigned RENUM    : 1; // bit 1

            unsigned DISCOE   : 1; // bit 2

            unsigned DISCON   : 1; // bit 3

            unsigned Reserved : 3; // bits 6-4

            unsigned WAKESRC  : 1; // bit 7

};

 

xdata at 0x7fd6 unsigned char byteUSBCS;

xdata at 0x7fd6 struct bitsUSBCS USBCS;

 

Here is the code I get when clearing bit 2 using the two different methods:

 

byteUSBCS &= ~0x04;

 

;     genAssign

;     genAnd

;       Peephole 248.b  optimized and to xdata

            mov     dptr,#_byteUSBCS

            movx    a,@dptr

            mov     r2,a

            anl     a,#0xFB

            movx    @dptr,a

 

USBCS.DISCOE = 0;

 

;     genPointerSet

;     genFarPointerSet

            mov      dptr,#_USBCS

;     genPackBits

            movx     a,@dptr

            anl        a,#0xfb

            movx     @dptr,a

 

Here is the code I get when setting bit 2 using the two different methods:

 

byteUSBCS |= 0x04;

 

;     genAssign

;     genOr

;       Peephole 248.a  optimized or to xdata

            mov     dptr,#_byteUSBCS

            movx    a,@dptr

            mov     r2,a

            orl     a,#0x04

            movx    @dptr,a

 

USBCS.DISCOE = 1;

 

;     genPointerSet

;     genFarPointerSet

            mov      dptr,#_USBCS

;     genPackBits

            movx     a,@dptr

            orl         a,#0x04

            movx     @dptr,a

--------------------------------------

 

The only difference I see is the temporary storage of the content of @dptr before the ANDing or ORing operation. Does this cause any problems in the evaluation of expressions containing bit fields or are bit fields safe to use? I’d much prefer using USBCS.DISCOE = 0 rather than byteUSBCS &= ~0x04.

 

-Stan