NeoLoch Home Page
Home

Products
Inquisitor IC Tester
4-Dig 7-Seg Display Module

Learning Lab
Assembly Cmds

Consulting
Shipping Policy

About us

Contact us

Support
Knowledgebase

Secured by PayPal
Official PayPal Seal
BTFSC Command:
Syntax:
Status Flags Effected:
BTFSC
BTFSC f,d
NONE
The BTFSC command is a branching command used to jump to different segments of code depending on the status of the bit being tested. Depending on the state of the bit being tested, the command will either execute the next line of code or skip that line in favor of the following line of code.

Code Example 1: Assume we have a register labeled FLAG. The following sequence of commands will jump to different segments of code depending on the state of bit 0.
BTFSC       FLAG,0
GOTO        DO_THIS
GOTO        DO_THAT
Test the value of  bit 0 in the register labeled FLAG.
If the bit = 1 then jump to this routine.
If the bit = 0 then jump to this routine.

Code Example 2: Same as above, but testing of bits 2 and 1 included.
BTFSC       FLAG,0
GOTO        DO_THIS
BTFSC       FLAG,1
GOTO        DO_THAT
BTFSC       FLAG,2
GOTO        DO_OTHER
...
Test the value of  bit 0 in the register labeled FLAG.
If the bit = 1 then jump to this routine.
Test the value of  bit 1 in the register labeled FLAG.
If the bit = 1 then jump to this routine.
Test the value of  bit 2 in the register labeled FLAG.
If the bit  = 1 then jump to this routine.
Additional code goes here for further testing or exiting the routine.

BTFSC can be used in conjunction with the command SUBWF to test if a specific value is met. A good example would be testing specific menu values to determine which menu item is selected.

Code Exampe3: In this example the BTFSC command is used in conjunction with SUBWF as a menu selection routine. This routine will use a register labeled CMD which will store the command recieved from the user.
MOVLW    0X00
SUBWF      CMD,W
BTFSC        STATUS,Z
GOTO         DO_1


MOVLW    0X01
SUBWF      CMD,W
BTFSC        STATUS,Z
GOTO         DO_1


MOVLW    0X02
SUBWF      CMD,W
BTFSC        STATUS,Z
GOTO         DO_1
Move the literal value 0x00 into the working register.
Subtract W from the value in CMD and store the result in W.
Is the zero flag in in the status register equal to 1?
Yes - command matched.

No - so let's check for the next command in the sequence.
Move the literal value 0x00 into the working register.
Subtract W from the value in CMD and store the result in W.
Is the zero flag in in the status register equal to 1?
Yes - command matched.

No - so let's check for the next command in the sequence.
Move the literal value 0x00 into the working register.
Subtract W from the value in CMD and store the result in W.
Is the zero flag in in the status register equal to 1?
Yes - command matched.

This routine works by relying on the zero flag (Z) in the status register. When we do the subraction with the command SUBWF if the result is zero then the Z flag in the status register is set. This allows us to test this flag to see if the subraction resulted in a zero.

We next test this bit using the BTFSC command. If the bit is clear (zero) then we'll skip the GOTO instruction and move on to the next command test. This process continues until we've tested all the commands and at the end of this a "RETURN" instruction would be placed to safely exit the routine.
Home Consulting Products About us Contact us
All contents of this website are copyrighted 2010-2011 NeoLoch, LLC