PIC Microcontoller Subtraction Math Method

16-bit subtract routine for PIC16 instruction set. valid C and Z



if you can do better (smaller), tell me! this is the best I could do.


;------------------------------
;19/6/2006
;code by Christian Blondin
;]b[e]l[t]o[i]d[9]7[@s@p@a@m@]e[m]a[i]l.c]o[m -> delete the [][][[] @spam@
;rsc-mirror3.netfirms.com/pic.html -> coming up.
;
;code is for PIC16 instruction set (PIC10F, 12F, 16F...)
;remove the last two lines if you don't need a valid zero flag.
;performs [f01|f00] = [f01|f00] - [f03|f02] while keeping f03|f02 intact.
;(f00 and f02 being the low-bytes, f01 and f03 the hi-bytes)
;briefly tested in MPSIM ("special cases" only)

	movf	f02,W
	subwf	f00,F		;f00-f02 (STATUS,C=!BORROW)
	movf	f03,W
	btfss	STATUS,C	;skip if borrow=0 (C=1)
	addlw	01
	subwf	f01,F		;f01-f03	STATUS,C=!BRW
	btfsc	STATUS,Z	;skip if MSbyte<>zero
	movf	f00,F		;else, check LSbyte for zero.
;------------------------------

Comments: