help regarding the btfss

Discussion in 'Embedded Systems and Microcontrollers' started by Ahmed Adel, Nov 27, 2009.

  1. Ahmed Adel

    Thread Starter Member

    May 12, 2008
    18
    0
    hi everybody ..

    if i write:

    Code ( (Unknown Language)):
    1.  
    2. btfss REG,3
    3. goto R1
    4. goto R2
    5.  
    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: Nov 27, 2009
  2. cheezewizz

    Active Member

    Apr 16, 2009
    82
    10
    Put a 'btfsc reg, 3' between the two instructions. So it looks like
    Code ( (Unknown Language)):
    1. btfss REG,3
    2. goto R1
    3. btfsc REG, 3
    4. goto R2
    So that way if it branches down R1 when it returns R2 will be skipped...
     
  3. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    763
    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.
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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
     
  5. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    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
     
  6. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,692
    901
    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
     
  7. Ahmed Adel

    Thread Starter Member

    May 12, 2008
    18
    0
    thaaaaanks alot all of u .. I admired the idea of cheezewizz .. and it worked properly ..
     
  8. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    763
    My suggestion was wrong. If the OP wanted a GOTO a CALL was not correct.

    Sorry for suggesting that! :(
     
Loading...