Branch on Less Than

Status
Not open for further replies.

MrJammin

New Member
I was looking at the PIC instruction set and could not find the equivalent of a Branch on Less Than or Branch on Greater Than that I have found in other assembly languages. Does this instruction not exist for the PIC microprocessors, if so, how do you recommend I circumvent the problem of not being able to use the BLT instruction.
 
You use the carry flag instead, but the subtract instructions are a bit weird. Sublw 5 does not subtract 5 from W - it subtracts W from 5.

So, you can do,
Code:
         sublw   5
         btfss    STATUS,C
         goto     W_was_greater_than_5

Mike.
 
Last edited:
That's very interesting. I'm a little new to flags, do I have to reset that carry flag if I want to use it in another later similar scenario?
 
The subtract instruction will set OR clear the flag depending on the result of the subtract.

Therefore the state of the carry flag doesn't matter before the subtract instruction executes.
 
I was looking at the PIC instruction set and could not find the equivalent of a Branch on Less Than or Branch on Greater Than that I have found in other assembly languages.
The 18F series PICs have these instructions. If you are using the 10,12 or 16F series you'll have to do as noted by Pommie above.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…