BTFSC Bit Operations

Test a bit and skip the next instruction if it is clear.

SyntaxBTFSC f, b
Operandsf: register address 0-127; b: bit number 0-7
Operationskip the next instruction if f<b> = 0
Status bitsNone
Words / cycles1 word, 1 (2 if it skips) cycles
Encoding01 10bb bfff ffff

How it works

BTFSC ("bit test f, skip if clear") checks bit b of register f. If the bit is 0, the next instruction is skipped; if it is 1, execution continues normally. The skipped instruction still takes a cycle, so a skip costs 2 cycles.

It is the PIC's conditional branch: put a GOTO after it to jump only when the bit is set.

Example

; BTFSC example from picsimulator.com/instructions/btfsc.html
    list p=16f84a
    include <p16f84a.inc>

    org 0
    clrf 0x21
    movlw 0x01
    movwf 0x20        ; bit 1 of 0x20 is clear
    btfsc 0x20, 1     ; clear, so skip
    incf 0x21, f      ; skipped
    incf 0x21, f      ; runs: 0x21 = 1

Bit 1 is 0, so the first INCF is skipped and 0x21 ends at 1.

Open this example in the simulator

Watch out for

  • Only one instruction is skipped. A two-word sequence (for example BANKSEL on a 4-bank device) after BTFSC will only partly be skipped.

Related instructions