Given the small amount of ram (128 bytes) in the x1101, I need to use bit arrays for a 64bit value. Is there a good/best way to do this?
I've done roughly the code below:

unsigned int bits[4];   // 16bit words x 4 = 64bits
getbit(bits, n) { return( (bits[n>>4] >> 15-(n&0xF)) & 0x1) ); }

However, it's really quite ugly compared to just  " bits[n] ",
I've also looked at the code generated, and it's quite bloated,
and given the ROM of a 1101 (1K), I can't really afford that either,
the shifting is not a single instruction on a MSP430.

The bits[n] generates just 8 bytes of code.
(bits[n>>4] >> 15-(n&0xF)) & 0x1)  generates 50 bytes

My most recent idea is to use something similiar with somewhat
less shifting, at least not the loop used above.

unsigned char bits[16];
getbit(bits, n) {
 int bits4 = bits[n>>2];
 switch (n & 0x3) {
  case 11: bits4 >>= 1;
  case 01: bits4 >>= 1;
  case 10: bits4 >>= 1;
  case 11: return bits4 & 1;
 }}

This generates 88 bytes...

there must be a simple way to do this that I'm just overlooking.
Perhaps some simple assembly code is the best approach?

thanks,
Kelly Murray


Reply via email to