> > Hello, I am trying to use a file register as a mask to clear a bit on > PORTB. I do get a warning when I compile: > > Warning[202] E:\PIC\CODE\test.ASM 113 : Argument out of range. Least > significant bits used. > > Here is the code: > Let's say test = 1 for argument's sake (I've tested this and it does) > movwf test ;save request > movlw .1 ;need to subtract 1 so range is from 0 to 7 > subwf test, W ;w = test - 1 > movwf test ;test = test - 1 test = 0 > bcf PORTB, test ;clear PORTB.0 > > It doesn't matter what bit I want to clear, bit five is the only one that > is ever cleared regardless of the value of test. I should point out that > test is in files register 0x015, so it makes sense why bit 5 (the lower > nybble) is the only one cleared, but why is it using it's address and not > it's value? Because the instruction doesn't have a way of representing the value. The bcf instruction only accepts a constant between 0-7. But fear not it can be done. You in fact need 8 bcf instructions and use a small jump table. Try this on for size. movwf test ; stick the bit to clear in test. decf test ; subtract one. Takes one less cycle than yours rlf test,W ; Double the value and stick back in W andlw 0xf ; make sure to make result in the jump table. addwf PCL,F ; Jump to the appropriate instruction bcf PORTB,0 ; Clear bit 0 goto done ; and finished. bcf PORTB,1 ; Clear bit 1 goto done ; and finished. bcf PORTB,2 ; Clear bit 2 goto done ; and finished. And so forth. The value in W coming in will select with pair of bcf, goto instructions to execute. I use this technique in my NPCI interpreter. To further generalize it the address of the target is placed in the FSR register and the bcf instructions are executed on INDF. That way the code can be applied against any register file in the system instead of just PORTB. Hope this helps, BAJ