; mymacros.inc ; Celio Guimaraes's PIC16F8X macros Nov 16 2001 NOLIST errorlevel 1, -305 ; suppress warning msg that takes f as default ; destination operand w EQU 0 f EQU 1 mov macro s,d ; general mov file register macro, implements one of: ; mov fr, w ; mov w, fr ; mov fr1, fr2 if s == 0 movwf d ; mov w, fr else if d==0 || d==1 movf s,d ;mov fr,d else movf s,0 ; mov fr1, fr2 movwf d endif endif endm movl macro k,w if w == 0 movlw k else error "literal cannot be moved to file register" endif endm xchg macro fr1,fr2 ; exchanges two registers using only W as scratchpad ;adapted from http://www.geocities.com/SiliconValley/Network/9276/useful.zip if fr1==fr2 error "no need to exchange a register with itself" else if fr2 != 0 movf fr2,0 endif xorwf fr1,1 xorwf fr1,0 xorwf fr1,1 if fr2 != 0 movwf fr2 endif endif endm add macro fr,d if fr == 0 && d >1 addwf d,1 ; w + d =>d (d should be a file register!) else addwf fr,d endif endm sub macro fr,d if fr == 0 error "1st operand must be a file register" else subwf fr,d endif endm ior macro fr,d if fr == 0 error "1st operand must be a file register" else iorwf fr,d endif endm xor macro fr,d if fr == 0 error "1st operand must be a file register" else xorwf fr,d endif endm addl macro k,w if w == 0 addlw k else error "literal cannot be added to file register" endif endm subl macro k,w if w == 0 sublw k else error "literal cannot subtract a file register" endif endm andl macro k,w if w == 0 andlw k else error "literal cannot be anded to file register" endif endm iorl macro k,w if w == 0 iorlw k else error "literal cannot be ored to file register" endif endm xorl macro k,w if w == 0 xorlw k else error "literal cannot be exclusive ored to file register" endif endm decbnz macro count,label if count == 0 error "1st operand must be a file register" else decfsz count goto label endif endm LIST