Moderadores: andre_luis, 51, guest2003, Renie
;*****************************************************************************************************
; 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
movfw valor1
subwf valor2,w
btfss status, c
goto isso ; valor1 > valor2
goto aquilo ; valor1 < ou = valor2
Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante