PIC Microcontoller Math Method

24 bit binary addition

From: Dwayne Reid

...here is an example that takes the value in R1H,M,L and adds it to the value contained in AD2H,M,L (result in AD2H,M,L). You should be able to see how to extend it to more than 24 bits.

There is a similar version that does subtraction. I often extend to 40 bits or more - its easier to do this when manipulating integer values than it is to try and figure out which bits I can discard.

;now add new sample
	mov	W, R1L	;
	add	AD2L, W	;LS byte

	mov	W, R1M	;middle byte
	snb	C
	movsz	W, ++R1M
	add	AD2M, W	;

	mov	W, R1H	;MS byte
	snb	C
	movsz	W, ++R1H
	add	AD2H, W	;