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.

16 Bit Subraction

Status
Not open for further replies.

Suraj143

Active Member
I have a 16bit subtract code. Can I tell one of the values greater or less than by looking at the CARRY bit?

I dont need the result I need to know what value is bigger or less.

Code:
Num_L,Num_H	=value to be subtracted

NumF_L,NumF_H	=fix value


[Num_H] [Num_L]= [Num_H] [Num_L] - [NumF_H] [NumF_L]

Sub16	movf	NumF_L,W
	subwf	Num_L,F
	movf	NumF_H,W
	btfss	STATUS,C
	addlw	.1
	subwf	Num_H,F
	btfss	STATUS,C

	;if carry set [Num_H] [Num_L] bigger
	;if carry not set [NumF_H] [NumF_L] bigger
 
when I don't need to know the result I use,
Code:
		movfw	Num1H		;compare high bytes
		subwf	Num2H,W
		btfss	STATUS,Z	;if same compare low bytes
		goto	GotResult
		movfw	Num1L
		subwf	Num2L,W
GotResult
;carry Set if Num1<=Num2

Mike.
 
when I don't need to know the result I use,
Code:
		movfw	Num1H		;compare high bytes
		subwf	Num2H,W
		btfss	STATUS,Z	;if same compare low bytes
		goto	GotResult
		movfw	Num1L
		subwf	Num2L,W
GotResult
;carry Set if Num1<=Num2

Mike.

Thats exactly what I need thanks for that.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top