help regarding the btfss

Thread Starter

Ahmed Adel

Joined May 12, 2008
18
hi everybody ..

if i write:

Rich (BB code):
btfss REG,3
goto R1
goto R2
hoping that R1 is executed if REG(3)=1 and R2 is executed when REG(3)=0 .. but what happens with me is like follows:

if REG(3)=1 then the program will jump one instruction, ignoring R1, jumpting to R2 .. nice ..

but if REG(3) = 0, program won't jump anywhere and it will execute R1 and sequentially executes R2 too .. so in the case of REG(3)=0, both R1 and R2 will be executed ..

how can i separate them .. plz help ..
 
Last edited:

cheezewizz

Joined Apr 16, 2009
82
Put a 'btfsc reg, 3' between the two instructions. So it looks like
Rich (BB code):
btfss REG,3
goto R1
btfsc REG, 3
goto R2
So that way if it branches down R1 when it returns R2 will be skipped...
 

atferrari

Joined Jan 6, 2004
4,771
Why do not use CALL instead? That is what I would do.

With GOTO you are creating a problem to yourself. You need extra code after it.
 

Markd77

Joined Sep 7, 2009
2,806
This is what I usually do:
btfss REG,3
goto R1
.....code to be executed if REG,3 = 1
.....
goto finished
R1
......code to be executed if REG,3 =0
.....
finished
 

BMorse

Joined Sep 26, 2009
2,675
Why do not use CALL instead? That is what I would do.

With GOTO you are creating a problem to yourself. You need extra code after it.
You might want to watch out using the call statement when a GOTO is more approriate at times, using call statements with out something to return to will cause a stack overflow error......

Goto in this case is more appropriate....

My. 02
 

jpanhalt

Joined Jan 18, 2008
11,087
Put a 'btfsc reg, 3' between the two instructions. So it looks like
Rich (BB code):
btfss REG,3
goto R1
btfsc REG, 3
goto R2
So that way if it branches down R1 when it returns R2 will be skipped...
Good idea, but isn't BTFSS skip if set? The OP wants R1 when Reg,3 is set. I think all you need to do is reverse R1 and R2.

John
 

atferrari

Joined Jan 6, 2004
4,771
You might want to watch out using the call statement when a GOTO is more approriate at times, using call statements with out something to return to will cause a stack overflow error......

Goto in this case is more appropriate....
My. 02
My suggestion was wrong. If the OP wanted a GOTO a CALL was not correct.

Sorry for suggesting that! :(
 
Top