Hi, I will do it this way (untested): clear_bit: movlw 0b10000000 movwf mask movf test,w addwf PCL,f ;carry is always clear rrf mask,f rrf mask,f rrf mask,f rrf mask,f rrf mask,f rrf mask,f rrf mask,f comf mask,w ;invert mask andwf PORTB,f ;clear bit Or: clear_bit: movlw 1 ;mask=2^test btfsc test,1 movlw 4 movwf mask btfsc test,0 addwf mask,f btfsc test,2 swapf mask,f comf mask,w ;invert mask andwf PORTB,f regards, Reggie -- e-mail: rberdin@bigfoot.com ICQ#: 31651436 URL: http://www.bigfoot.com/~rberdin Byron A Jeff wrote: > > 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. >