Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 18th August 2008, 03:01 AM   (permalink)
Default 3 Digit Subtraction < or >

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
Suraj143 is offline  
Old 18th August 2008, 04:35 AM   (permalink)
Default

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.
Pommie is offline  
Old 18th August 2008, 05:16 AM   (permalink)
Default

Quote:
Originally Posted by Pommie View Post
I'm assuming that D3 is the most significant byte.
Excellent it is correct.That is what I needed.I started from LSB, its better do the math part from MSB side like you did.

Thanks Mike
Suraj143 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Voltage Subtraction JPW1966 General Electronics Chat 2 24th October 2007 10:58 PM
subtraction instruction in pic 4electros Micro Controllers 10 13th August 2005 08:02 PM
PIC subtraction: Carry flag eblc1388 Micro Controllers 4 19th June 2005 02:47 PM
subtraction in PIC16F876 ?? zika1212 Micro Controllers 1 21st December 2004 01:14 AM
Background Subtraction scout_54 Electronic Projects Design/Ideas/Reviews 1 16th March 2004 02:05 AM



All times are GMT. The time now is 03:48 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker