Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 11th June 2007, 03:35 PM   #1
Default Branch on Less Than

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.
MrJammin is offline  
Old 11th June 2007, 04:03 PM   #2
Default

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 by Pommie; 13th June 2007 at 01:02 AM.
Pommie is online now  
Old 11th June 2007, 08:37 PM   #3
Default

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?
MrJammin is offline  
Old 11th June 2007, 10:48 PM   #4
Default

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.
__________________
Pete
picprojects.org.uk
geko is offline  
Old 12th June 2007, 03:28 AM   #5
Default

Quote:
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.
__________________
Inside every little problem, is a big problem trying to get out.
kchriste is offline  
Reply

Tags
branch

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Readily Available 8ch, 10-12bit A/D buurin General Electronics Chat 37 29th September 2006 04:23 PM
carry and digit carry definition max_imum2000 General Electronics Chat 6 8th May 2006 05:40 PM
obvious questions..... madmikejt12 General Electronics Chat 21 7th October 2005 09:26 PM
Just Joined, Got some bugs I can't find. Thedoctorisin136 Micro Controllers 0 1st March 2005 07:07 PM



All times are GMT. The time now is 04:15 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker