PIC12 and PIC16


;***********************************************
;********** USEFUL DEFINES AND MACROS **********
;***********************************************
#define	skip_if_c	btfss	status,c
#define	skip_if_nc	btfsc	status,c
#define	skip_if_z	btfss	status,z
#define	skip_if_nz	btfsc	status,z

;compare file to w, skip if f=w
cpfseq_macro	macro	reg
	xorwf	reg,w
	skip_if_z
	endm
;
;compare file to w, skip if f<>w
cpfsneq_macro	macro	reg
	xorwf	reg,w
	skip_if_nz
	endm
;
;compare file to w, skip if f>=w
cpfsgt_eq_macro	macro	reg
	subwf	reg,w
	btfss	status,c
	endm
;
;compare file to w, skip if f>w
cpfslt_macro	macro	reg
	subwf	reg,w
	btfsc	status,c
	endm

;16 BIT COMPARE MACRO - UNBANKED
compare_a_b_16bit_agtb_bgta_aeqb macro	reg_a_h, reg_a_l, reg_b_h, reg_b_l
	movfp	reg_b_h,wreg
	subwf	reg_a_h,w				;A_h - B_h
	btfss	status,z				;is result zero (A and B high are the same)?
	goto	$+d'05'					;no
	movfp	reg_b_l,wreg				;yes - do low byte
	subwf	reg_a_l,w				; A_l - B_l
	btfsc	status,z				;is result zero (A and B low are the same)?
	goto	$+4					;yes - a and b are equal
	btfsc	status,c				;is A higher than B ?
	;a > b						;Yes
	;b > a						;No
	;a = b
	endm
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.