Bit Addresses for I/O and RAM


Many microprocessors such as X86 and Pentium allow programs to access registers and I/O ports in byte size only. In other words, if you need to check a single bit an I/O port, you must read the entire byte first and then manipulate the whole byte with some logic instructions to get hold of the desired single bit. This is not the case with the 8051. Indeed one of the most important feature of the 8051 is the ability to access the registers, RAM, and I/O ports in bits instead of bytes.    

Bit-Addressable RAM:

Of the 128-byte internal RAM of the 8051, only 16 bytes are bit-addressable. The rest must be accessed in byte format. The bit-addressable RAM locations are 20H-2FH. These 16 bytes provide 128 bits (16*8=128) of RAM bit addressability. They are addressed as 0 to 127 or 00 to 7FH. Therefore, the bit addresses 0 to 7 are for the first byte of internal RAM location 20H, and 8 to 0FH are the bit addresses of the second byte of RAM location 21H, and so on. The last byte of 2FH has bit addresses of 78H to 7FH.

As shown in the below table internal RAM locations 20-2FH are both byte addressable and bit addressable.