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
BTFSS Command:
Syntax:
Status Flags Effected:
BTFSS
BTFSS f,d
NONE
The BTFSS 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.
BTFSS       FLAG,0
GOTO        DO_THIS
GOTO        DO_THAT
Test the value of  bit 0 in the register labeled FLAG.
If the bit = 0 then jump to this routine.
If the bit = 1 then jump to this routine.

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

BTFSS 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 BTFSS command is used in conjunction with SUBWF to test if a string matches the data recieved from the user. An array CMD+0 through CMD+2 containes that data string.
MOVLW    "1"
SUBWF      CMD+0,W
BTFSS        STATUS,Z
RETURN


MOVLW    "2"
SUBWF      CMD,W
BTFSS        STATUS,Z
RETURN


MOVLW    "3"
SUBWF      CMD,W
BTFSS        STATUS,Z
RETURN
...
Move the ASCII value for "1" 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?
No - character doesn't match so exit routine.

Yes - so let's check for the next letter in the string.
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?
No - character doesn't match so exit routine.

Yes - so let's check for the next letter in the string.
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?
No - character doesn't match so exit routine.
Proceed to execute code associated with the string "123"

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 BTFSS command. If the bit is set (one) then we'll skip the RETURN instruction and move on to the next character test. This process continues until we've tested all the characters and at the end of the string test, we can execute the code associate with the command..
Home Consulting Products About us Contact us
All contents of this website are copyrighted 2010-2011 NeoLoch, LLC