Accessing Bitfields

Mask and shift operations involved in packing or unpacking bitfields cause inefficient bitfield accesses. To increase efficiency when accessing bitfields only one bit wide, use direct addressing mode, the BSET/BCLR instruction, and the bit branches BRSET and BRCLR.

To enable direct addressing, declare the bitfield in the zero page using the DATA_SEG__SHORT_SEG pragma (refer the following listing).

Listing: Example
#pragma DATA_SEG __SHORT_SEG DATA_ZEROPAGE;
struct {

  int a:1;

} bf;

void main(void) {

  bf.a = -1;

}