Comparison macro for PIC processors

Dennis M Nagel, Dennis M Nagel Inc, Delray Beach, FL -- EDN, 3/2/2000

If you ever get tired of trying to remember the subtleties of the "carry" status bit every time you want to use the subtract instruction to perform a comparison, the macro in Listing 1 can help. The macro contains all of the nuances, once and forever. The macro reads like a sentence: branch to target if ram-register is [comparison condition] a literal value. The comparison conditions available are "equal-to," "not-equal-to," "below," and "above-or-equal." The words "below," "above," and others adhere to the Intel/Microsoft assembly-language convention of referring to "unsigned" comparisons for which the byte value can range only from 0x00 (decimal zero) to 0xFF (decimal 255).

Although you can use this macro for "equal" and "not-equal" comparisons, its real power comes in examining a value in a range or in a window of values. As an example of the macro's use, suppose you want to execute some code, but only if some ram-register is 0x6C or more but not greater than 0x93 (0x94 to 0xFF). You would use:

b2 continue_label1, ram-register, b1, 0x6C
b2 continue_label1, ram-register, ae, 0x94
.
source code here to execute only if ram-register = 0x6c to 0x94 inclusive.
.
continue_label1:
A variation of usage is available if you want to perform a comparison between a ram-register and the "W" register instead of a literal value. An example of this usage is:

b2 continue_label2, ram-register, b2, WREG
.
source code here to execute only if ram-register is below (less than and not equal to) the current value in the W register.
.
continue_label2:

Note that these examples destroy the value in the "W" register. (DI #2493)




ADVERTISEMENT

ADVERTISEMENT

Feedback Loop


Post a CommentPost a Comment

There are no comments posted for this article.

Related Content

 

By This Author

There are no additional articles written by this author.


ADVERTISEMENT

Knowledge Center



Technology Quick Links

EDN Marketplace


©1997-2008 Reed Business Information, a division of Reed Elsevier Inc. All rights reserved.
Use of this Web site is subject to its Terms of Use | Privacy Policy

Please visit these other Reed Business sites

ADVERTISEMENT
You will be redirected to your destination in few seconds.