Keil Logo

Bit-Addressable Objects

Bit-addressable objects are objects that can be addressed as words or as bits. Only data objects that occupy the bit-addressable area (bdata) of the C16x/ST10 internal memory fall into this category.

The C166 Compiler places variables declared with the bdata memory type into the on-chip bit-addressable area. Variables declared with the bdata type must be global. You may declare these variables as follows:

int bdata ibase;        /* Bit-addressable int */

char bdata bary [4];    /* Bit-addressable array */

The variables ibase and bary are bit-addressable and the individual bits of these variables can be directly accessed and modified. Use the sbit keyword to declare new variables that access the bits of variables declared using bdata.

The following example shows declarations, not assignments, to the bits of the ibase and bary variables.

sbit mybit0 = ibase ^ 0;      /* bit 0 of ibase */
sbit mybit15 = ibase ^ 15;    /* bit 15 of ibase */

sbit Ary07 = bary[0] ^ 7;     /* bit 7 of bary[0] */
sbit Ary37 = bary[3] ^ 7;     /* bit 7 of bary[3] */

The expression following the carat symbol ('^') in the example, specifies the position of the bit to access with this declaration. The expression must be a constant value. The range depends on the type of the base variable included in the declaration. The range is 0-7 for char and unsigned char, 0-15 for int, unsigned int, short, and unsigned short, and 0-31 for long and unsigned long.

You may provide external variable declarations for the sbit type to access these types in other modules. For example:

extern bit mybit0;      /* bit 0 of ibase */
extern bit mybit15;     /* bit 15 of ibase */

extern bit Ary07;       /* bit 7 of bary[0] */
extern bit Ary37;       /* bit 7 of bary[3] */

Declarations involving the sbit type require that the base object is declared with the bdata memory type. The only exceptions are the special function register bits. Refer to sfr Types for more information.

The following example shows how to change the ibase and bary bits using the above declarations.

Ary37 = 0;        /* clear bit 7 in bary[3] */
bary[3] = 'a';    /* Byte addressing */
ibase = -1;       /* Word addressing */
mybit15 = 1;      /* set bit 15 in ibase */

The bdata memory type is handled like the idata memory type except that variables declared with bdata reside in the bit-addressable portion of the on-chip data memory. Note that the total size of this area of memory cannot exceed 256 bytes.

In addition to declaring sbit variables for scalar types, you may also declare sbit variables for structures and unions. For example:

union lft
  {
  float mf;
  long ml;
  };

bdata struct bad
  {
  char m1;
  union lft u;
  } tcp;

sbit tcpf31 = tcp.u.ml ^ 31;        /* bit 31 of float */
sbit tcpm10 = tcp.m1 ^ 0;
sbit tcpm17 = tcp.m1 ^ 7;

Note

  • You may not specify bit variables for the bit positions of floating-point variable types. However, you may include floating-point types and integer types in a union and declare bit variables to access the bits in the integer part of the union.
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.