Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

3 Digit Subtraction < or >

Status
Not open for further replies.

Suraj143

Active Member
Hi I have a pair of 3 digit values. They are actual value & save value.

I need to subtract the save value from the actual value & need to decide is it greater than the save value.

I don’t need the exact result I need to know whether actual value > or < than the save value.

I wrote a small routine needs to check is it ok or not,

Code:
121	=actual value	(D3,D2,D1)
103	=save value	(SD3,SD2,SD1)


	movf	SD1,W
	subwf	D1,W		;substract digit1
	btfsc	STATUS,C
	goto	$+2
	decf	D2,F
	movf	SD2,W
	subwf	D2,W		;substract digit2
	btfsc	STATUS,C
	goto	$+2
	decf	D3,F
	movf	SD3,W
	subwf	D3,W		;substract digit3
	btfss	STATUS,C
	goto	$+3
	bsf	Result,1	;result	possitive
	return
	bcf	Result,1	;result	negative
	return
 
You can do a much simpler comparison by just comparing the digits until you find a pair that are not equal. I'm assuming that D3 is the most significant byte.
Code:
		movfw	D3
		subwf	SD3,W
		btfss	STATUS,Z
		goto	GotResult
		movfw	D2
		subwf	SD2,W
		btfss	STATUS,Z
		goto	GotResult
		movfw	D1
		subwf	SD1,W
GotResult
		
;if zero flag set then numbers are equal
;if carry flag set then SD > D

Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top