At 12:13 1/11/99 +1100, you wrote: >John Considine wrote: >> >> I am trying to have a variable be decremented and that result be used as >> the BTFSC test bit >> >> For example >> >> movlw H'07' >> movwf TestBit >> decf TestBit, 1 >> btfsc PORTB, TestBit >> >> Is this possible, I tried using indirect referencing like >> >> movlw TestBit >> movwf FSR >> btfsc PORTB, INDF >> >> but that will not work. Any suggestions. >> Thanks > >You cannot use BTFSC like that. (?) > >You may need to try something like... > > movlw b'10000000' > movwf TestBit > > - - - - > > bcf status,carry ; shift bit one position to right > rrf TestBit > btfsc status,carry ; if carry = 1 then reset bit 7 = 1 > rrf TextBit > > - - - - > > movf PORTB,w ; do bit comparison on port > andwf TestBit,w > btfsc status,Z > goto BitIsOne > >-- >Best regards > >Tony > >http://www.picnpoke.com >Email sales@picnpoke.com > > I realy can't see what is going on here, If you are decementing to see what the results is you can have either a 1 or a 0, no matter what. Or is it that you are trying to use this as a mask for testing of each potential bit location. Ah yes the latter If the latter is true, then there is the problem in that the compiler + opcodes expect this to be a litteral value, hence the method used by Tony. E.G BTFSC myval, 0-7, where the 0 to 7 are fixed. If this is the case then perhaps you could waste a bit of space and use a table type function ;Test byte is the location to be compare d with the counter ;value. This makes the code resuable for testing of bit ;compares for any direct RAM location movf PORTB movwf test_byte,w ;do this bit on pre entry counter ;the current bit location to look at ;the counter is 0-7 and indicates the bi t that we want to look ;at. Note that this vale must be preload ed and maintained by ;the calling code ;function body ;*********** bit compare: ;*********** ; Perequsites ; =========== ; Counter must be set with the bit to test ; w must contain the table offset ; test_byte must be the byte to test to ; LOCAL variable :- test_byte -> effectiv e only, not to be preserved movlw 3 ;so that we get to the correct location in the table addw counter add pcl,w ;point to the location to jump to TABLE nop nop nop btfsc test_byte,0 goto return_true goto return_false btfsc portb,1 ... return_true do stuff return_false do other stuff I know that there is stuff missing in the table but you can get the general idea. Tonys stuff also works, but resides on the assumption that the value (As you requested) is dectmented by one each time, where the table value lets you attack any bit at any time. On further thinking Tonys way on bit test will work at all times, so ignore the rubbish I just came up with Dennis