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.

How to check whether it is ZERO or not?

Status
Not open for further replies.

Suraj143

Active Member
Hi I have a COUNT variable. When power up the PIC don’t know what value in it. (It depends on the last saved value in EEPROM)

I want to check whether it is ZERO or other. If it is zero I want to goto NORMAL program. If not zero I want to goto UPDATE routine.

Here is my code please tell me am I right?

Code:
	movf	COUNT,W		;get the count value
	xorlw	00h		;compare with zero
	btfss	STATUS,Z	;check the ZERO bit
	goto	UPDATE		;NO, it is not ZERO
	goto	NORMAL		;YES, it is ZERO
 
Yep that'll work. MPASM also has a couple of macros built in to make that eaiser.

so..

Code:
  movf   COUNT,W   ;sets the z flag
  bz     NORMAL    ;it's zero so branch
  goto   UPDATE    ;not zero so goto UPDATE
PS movf will set the zero flag, you don't need the xor.
 
Another useful way to test for zero is movf COUNT,F. This will set/clear the zero flag without corrupting W.

Mike.
 
Oh I see now I got it.Everywhere I'm corrupting W I must prevent this by moving the value to the FILE register.

Also built in macros really helpful.I must give a try for that.

Thank you both of you for the instant replies.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top