Steven Addison wrote: > I need to check that a value, which will be a slightly variable code > value, is between an upper and a lower threshold (or not). > > The way I have thought of doing it is to subtract it from the upper > threshold and retain the result, then subtract the lower threshold > from it and retain that result. If the two results are positive then > the code is within the limits and is good but if either are less > than zero then the code is no good. > > Here is my problem: How do I check for a <0 (negative) value in a > PIC register? Steve: It's simple. After a subtraction, the Carry flag is set if the result is positive, clear if it's negative. Assuming that all three values (your code, the upper threshold, and the lower threshold) are 8-bit unsigned numbers, and that you're using a 16Cxx part (NOT a 16C5x), the code to do what you want looks like this: MOVF CODE,W ;W = the value you're testing. ADDLW -LOWER ;Is it lower than "LOWER"? BNC BAD ;If so, it's bad. Jump. ADDLW -(UPPER-LOWER) ;Otherwise, is it higher than "UPPER"? BC BAD ;If so, it's bad. Jump. NOP ;Otherwise, it's good. Do whatever here... For those of you who care about such things, the standard "This code has neither been tested nor assembled; you get what you pay for" disclaimer applies. -Andy Andrew Warren - fastfwd@ix.netcom.com Fast Forward Engineering, Vista, California http://www.geopages.com/SiliconValley/2499