Look-up table facilitates bit flipping
Brad Bierschenk, High End Systems, Austin, TX -- 11/23/2000
In certain instances in embedded software, it becomes necessary to flip
the order of bits in a byte, so that B7:B0 becomes B0:B7. For example, this
feature could be useful with a synchronous serial port that does not allow
programmed selection of bit order (MSB first or LSB first) for its shift
register. If a device to which the processor sends data expects one bit order
but the serial port can provide only the other bit order, you must use a
software method to translate the data. One solution to this problem is to
provide a look-up table in ROM, in which the value of each byte in the table is
offset into the table, but with bit order reversed. In other words, the first
byte is offset 0 (00000000b), the second byte is offset 1 (10000000b), the third
byte is offset 2 (01000000b), and so on.The program merely needs to load the value to be translated into a register that can serve as an offset, index the look-up table, and load the corresponding value from the index+offset location. This design uses the Philips 80xC51 architecture as an example. Listing 1 shows a code segment for the µC. You can use the µC's 16-bit DPTR (data pointer) plus an 8-bit offset in its accumulator to load the accumulator with a byte value. This solution to bit flipping is dynamically more efficient than rotating a byte location through carry bits or other possible solutions. However, it's not the most statically efficient solution, because it requires 256 bytes of ROM for the look-up table.
ADVERTISEMENT
© 2009, Reed Business Information, a division of Reed Elsevier Inc. All Rights Reserved.

