C Memory – Understanding Addressable Memory Units

cmemory

From Wikipedia:

the term endian or endianness refers
to the ordering of individually
addressable sub-components within a
longer data item as stored in external
memory (or, sometimes, as sent on a
serial connection). These
sub-components are typically 16- or
32-bit words, 8-bit bytes, or even
bits
.

I was wondering what "addressable" means?

For example, in C, the smallest addressable is a byte/char. How can a bit be addressable?

Thanks and regards!

Best Answer

How can a bit be addressable?

The 8051/8052 family and some other microcontroller architectures (low and mid-range PIC, Infineon C16x/STM ST10) support bit-addressable addressing. In the 8051, the RAM bytes from 0x20 to 0x2f are bit addressable (128 bits in total). Also, many of the special function registers (SFR's) are bit addressable as well (in particular, those with byte addresses ending in 0 or 8 for the 8051 architecture).

8051 bit addressable memory

To support this, the 8051 has a number of instructions that operate directly on bits, such as set/clear/complement bit, jump if bit is set/not set, etc. These are much more efficient that loading up a general-purpose register and using AND or OR instructions.

For example, the instruction to set bit 3 of byte address 0x2A would be (the value 53h is found in the above table):

SETB 53h

which is a 2-byte, 1 cycle instruction.

Likewise, most C compilers for the 8051 (for example Keil C51) support a "bit" type in addition to standard C types like char, short, int etc. C statements referencing bit variables are compiled into code using the bit-manipulation assembly instructions.

So the code:

bit flag;
  .
  .
  .
flag = 1;

would compile into a single SETB instruction like the example above.

EDIT:

Regarding endianness on bit addressable machines, in general bits in a byte are labelled 7 to 0 (MSB to LSB), as in the diagram above. This is true whether the byte endianness is big endian like Motorola 6800, 68000 and PowerPC, or little endian like the 6502 family, Intel x86, and Amtel AVR.

Oddly, DEC minicomputers 50 years ago used the reverse notation: the PDP-8 numbered bits 0 to 11 (MSB to LSB). These machines were not bit-addressable however. DEC changed to the more common form used today when they came out with the PDP-11.

PDP-8 instruction format