On Thu, 2014-05-01 at 17:11 -0400, Larry Bradley wrote: > Thanks. Somewhere I read that the bitfield stuff was not efficient. >=20 > I tried it. The code using bitfields was the same size as using a mask. > And the mask code is a bit (no pun intended) clearer! I'm kind of surprised nobody compared the generated code. The code produced by XC16 is identical: if ( myBits & 0x0002 ) myTestWord =3D 87; if (myBitfield.b1) myTestWord =3D 83; 53: if ( myBits & 0x0002 ) 00029A 804000 MOV myBits, W0 00029C 600062 AND W0, #0x2, W0 00029E 500FE0 SUB W0, #0x0, [W15] 0002A0 320002 BRA Z, 0x2A6 54: myTestWord =3D 87; 0002A2 200570 MOV #0x57, W0 0002A4 884020 MOV W0, myTestWord 55: =20 56: if (myBitfield.b1) 0002A6 BFC802 MOV.B myBitfield, WREG 0002A8 604062 AND.B W0, #0x2, W0 0002AA 504FE0 SUB.B W0, #0x0, [W15] 0002AC 320002 BRA Z, 0x2B2 57: myTestWord =3D 83; 0002AE 200530 MOV #0x53, W0 0002B0 884020 MOV W0, myTestWord The real question is, does the optimizer have better luck with one over the other. Problem with that is that it is real hard to come up with bogus code the optimizer won't simply optimize out of existence. I would argue that the mask code is only clearer if 1) You are doing some bogus example like this or 2) You are an assembler programmer With the bitfield you can give the bits names, so for example you could say something like: if ( LCDstatus.LCDisBusy ) rather than if ( LCDstatus & 0b0000000000100000 ) Granted, you could say #define LCDBUSY 0x0020 then if ( LCDstatus & LCDBUSY ) but I still don't find that as clear as the bitfield example, which is probably why Microchip goes to the trouble of naming all the bits in the status words. You can even give the bit a macro name, making the code even more clear. Something Microchip does with many of the SFR bits. So with a define I could simply say if ( BUSYBIT ) far more readable than if ( LCDstatus & 0b0000000000100000 ) --McD --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .