It may worth to try the switch case structure that should compile to something similar to the jump table in your example: switch ( i ) { case 7: *pbuf++ <<=3D 1 +c; case 6: *pbuf++ <<=3D 1 +c; ..... case 1: *pbuf++ <<=3D 1 +c; case 0: *pbuf++ <<=3D 1 +c; } Tam=E1s On 2/28/10, Scott Dattalo wrote: >> Hi All, >> >> I browsed the PICList source library, but couldn't find anything >> similar to what I was looking for. >> >> I have a buffer of "packed" "bytes" where each byte is less that >> 8-bits in length. >> >> This buffer is generated by capturing a bitstream (LSB first) and >> right shifting in to the LSB of a buffer. >> >> e.g. for bytes sized 7 bits, if the first byte is all ones, the second >> is all zeros, and the third is all ones, >> my buffer looks as such: >> >> 01111111 >> 11000000 >> xxx11111 >> xxxxxxxx >> ... >> >> What I would like to do is break each "byte" out of the buffer and put >> it into another buffer, e.g. >> >> 01111111 >> 00000000 >> 01111111 >> 0xxxxxxx >> 0xxxxxxx > > Hi Scott, > > Here's an untested 18F version: > > lfsr 0,packedBuffer ; Source > lfsr 1,packedBuffer ; Source (used as a temporary) > lfsr 2,unpackedBuffer ; Destination > movlw numberOfBytes > movwf count > > loop: > movf indf0,W ; Get the next packed byte > andlw 0x7f > movwf postinc2 ; And save it unpacked > > movf count,W ; Are more than 7 bytes left? > sublw 7 > skpc > bra rotate7 ; There are more than 7 left so rotate them > > addwf WREG,W ; multiply (7-count) by 2 > addlw low(rotate7) ; And only rotate what's remaining > skpnc > incf PCLATH,F > movwf PCL > rotate7: > rlcf postinc0,F > rlcf postinc0,F > rlcf postinc0,F > rlcf postinc0,F > rlcf postinc0,F > rlcf postinc0,F > > movf postinc1,W ; Increment FSR1 (don't care about W) > movff FSR1L, FSR0L > movff FSR1H, FSR0H > > decfsz count,F > bra loop > return > > Here's the untested C-version > > void unpackBuffer(unsigned char *pSrc, unsigned char *pDest, unsigned char > size) > { > unsigned char i,j; > > for (i=3D0; i { > unsigned char *pTemp; > unsigned char carryIn; > unsigned char carryOut; > > // copy the source to the destination > *pDest++ =3D *pSrc & 0x7f; > > pSrc++; > > // Rotate the next 7 bytes (if 7 or more are left) > j =3D i > 7 ? 7 : i; > > // The MSB needs to be moved to the LSB of > // of the next byte > > carryOut =3D (*pSrc++ & 0x80) ? 1 : 0; > pTemp =3D pSrc; > while (j) > { > carryIn =3D carryOut; > > // Get the carry for the next byte > carryOut =3D (*pTemp & 0x80) ? 1 : 0; > > // rotate this byte and pick up carry from previous > *pTemp =3D (*pTemp << 1) + carryIn; > > // Point to the next > pTemp++; > } > } > > > I imagine the assembly version is a little faster. > > Scott > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- = Sent from my mobile device int main() { char *a,*s,*q; printf(s=3D"int main() { char *a,*s,*q; printf(s=3D%s%s%s, q=3D%s%s%s%s,s,q,q,a=3D%s%s%s%s,q,q,q,a,a,q); }", q=3D"\"",s,q,q,a=3D"\\",q,q,q,a,a,q); } -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist