Subscribe to EDN
RSS
Reprints/License
Print
Email

Comparison macro for PIC processors

Dennis M Nagel, Dennis M Nagel Inc, Delray Beach, FL -- EDN, March 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)


RSS
Reprints/License
Print
Email
Talkback
Canon Resource Center

Featured Company


Most Recent Resources

Advertisement
Related Content

No related content found.

  • 0 rated items found.
Advertisement

KNOWLEDGE CENTER

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
Engineering Careers
Jobs sponsored by
Advertisement
About EDN   |   Site Map   |   Contact Us   |   Subscription   |   RSS
© 2012 UBM Electronics. All rights reserved.
Use of this Web site is subject to its Terms of Use | Privacy Policy

Please visit these other UBM Canon sites

UBM Canon | Design News | Test & Measurement World | Packaging Digest | EDN | Qmed | Pharmalive | Appliance Magazine | Plastics Today | Powder Bulk Solids | Canon Trade Shows