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.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…