> Byron A Jeff wrote: > >> proc clearbits(copy char count, copy char start) >> while (count) >> portb:start = 0 // Clear the bit in PORTB referenced by >> // start. >> start = start+1 >> count = count-1 >> endwhile >> endproc >> >> The portb:start=0 line is a significant chunk of code because it >> represents a variable bit number. But the compiler gives a compact >> abstraction for the concept. The point of the code that I sent regarding this is that sometimes brute force is not the way to go. My trick of anding two masks together so that all the bits can be zapped at once means that the code is probably faster (except for very small values of 'count') and also probably shorter. Perhaps if the same concept were expressed in "C" it would make more sense to some.... const unsigned char mask_table[9] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80,0x00 }; void clearbits(unsigned char start, unsigned char count) { PORTB &= ~make_mask(start,count); } unsigned char make_mask(unsigned char start, unsigned char count) { return mask_table[start] & ~mask_table[start+count]; } Notice, no loops and pretty simple code. I would be tempted to turn make_mask into a #define: #define make_mask(start,count) (mask_table[(start)] & ~mask_table[(start)+(count)]) If you have a processor that can do multibit variable width shifts quickly then you can create an even faster make_mask: unsigned char make_mask(unsigned char start, unsigned char count) { return (0xFF << start) &~ (0xFF << (start+count)); } This could of course also be turned into a macro. Bob Ammerman RAm Systems _______________________________________________ http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist