di2493.txt ;***************************************************************************************************** ; LISTING 1 - COMPARISON MACRO ; ; "Comparison macro for PIC processors," EDN, March 2, 2000, pg 122 ; ; http://www.ednmag.com/ednmag/reg/2000/030200/designideas.htm#05di4 ;**************************************************************************************************** #define eq 1 ; if equal #define ne 2 ; if not equal #define bl 3 ; if below (unsigned comparison) #define ae 4 ; if above or equal (unsigned) #define WREG 0xFFFD ; if immediate-value specified as the W reg b2 MACRO target, ram_reg, cond, lval nolist if lval != WREG ; if lval spec'd as "WREG", don't move lval to W movlw lval endif ; subtract will set carry if ram_reg >= lval, clear it if reg < lval (unsigned) subwf ram_reg, W ; ram_reg minus W -> W, ram_reg unchanged if cond == eq ; if cond is "eq", skip if non 0, branch if 0 skpnz else if cond == ne ; if cond is "ne", skip if 0, branch if non 0 skpz else if cond == bl ; if cond is "bl", skip if carry, branch if not skpc else if cond == ae ; if cond is "ae", skip if not carry, else branch skpnc else ; if condition none of the above, error error "b2 macro condition argument not a valid choice" endif ; cond = ae endif ; cond = bl endif ; cond = ne endif ; cond = eq b target ; skip this if condition not true, take it if true list ENDM ; b2