> > Sorry, I didn't put it clear. > > test_for_bit equ 0x27 > value_to_test equ 0x26 > > Say value 5 is stored in the file register 0x27 > I would like to test the bit of . > > BTFSS value_to_test,[value stored in test_for_bit] -> Test the bit5 in the > value stored at 0x26 There's no instruction that can do that. As posted before there's a couple of ways of solving the problem. 1. Shift the bit to bit 0 then test bit 0. 2. Use a jump table to convert the bit number into a bit mask then apply the mask to the original value. 3. Use a jump table with two instruction each that does the appropriate bit test then a jump to the end. I use this technique in my NPCI interpreter. > > But the value stored in 0x27 will keep changing with program execution. > Say, after sometime( may be while in a loop), 0x27 holds the value 3, then > the same statement must test the bit3 of the value stored at 0x26. > > Something like: I would like to count the number of 1's in the value ( at > 0x26) using btfss instruction. Now that's a different problem. The fastest way to do this is to have a 256 byte jump table that takes the number and returns the number of bits. Probably even better would be to half the table an test, then zero, the high bit of the value under test. Then the table till only be 128 bytes long. The shortest way is to use technique 1 listed above. Instead of using a counter to variably test the bits of value_to_test, keep the same loop and shift the value_to_test (vtt) 1 bit to the right/left each time through the loop, testing the single bit at the end each time. So if the vtt is 10110101 You test bit 0, see that it's a one an increment the number of ones (noo) count. Then you shift one bit to the right getting 01011010 Test bit 0 again. Now the bit to test is fixed, which the PIC does no problem. Now since it's 0, the noo stays put. Repeat until the vtt is 0 (or exactly 8 counts if you like). When done the noo has the number of ones. Hope this helps, BAJ