# Stupid Zero Flag question

Discussion in 'Embedded Systems and Microcontrollers' started by daredavel, Mar 11, 2010.

1. ### daredavel Thread Starter Member

Feb 22, 2010
32
0
hi guys! can you help me understand the zero flag in assembly?

example:

(Count = h '3')

movf Count, W
xorlw 3
btfss Status, 2
goto next
goto next1

How can i determine the zero flag sir if it is set or not? Sorry for the stupid question..its my first encounter with the zero flag.. thank you!!

2. ### rjenkins AAC Fanatic!

Nov 6, 2005
1,015
69
Hi,

the instruction

btfss Status, 2

is determining if the Zero flag is set.

The status register bits have these meanings:
(Taken from a Microchip PIC datasheet)

Code ( (Unknown Language)):
1. bit 7 IRP: Register Bank Select bit (used for indirect addressing)
2.     1 = Bank 2, 3 (100h - 1FFh)
3.     0 = Bank 0, 1 (00h - FFh)
4. bit 6-5 RP1:RP0: Register Bank Select bits (used for direct addressing)
5.     11 = Bank 3 (180h - 1FFh)
6.     10 = Bank 2 (100h - 17Fh)
7.     01 = Bank 1 (80h - FFh)
8.     00 = Bank 0 (00h - 7Fh)
9.     Each bank is 128 bytes
10. bit 4 TO: Time-out bit
11.     1 = After power-up, CLRWDT instruction, or SLEEP instruction
12.     0 = A WDT time-out occurred
13. bit 3 PD: Power-down bit
14.     1 = After power-up or by the CLRWDT instruction
15.     0 = By execution of the SLEEP instruction
16. bit 2 Z: Zero bit
17.     1 = The result of an arithmetic or logic operation is zero
18.     0 = The result of an arithmetic or logic operation is not zero
19. bit 1 DC: Digit carry/borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions (for borrow the polarity is reversed)
20.     1 = A carry-out from the 4th low order bit of the result occurred
21.     0 = No carry-out from the 4th low order bit of the result
23.     1 = A carry-out from the most significant bit of the result occurred
24.     0 = No carry-out from the most significant bit of the result occurred
25.
By testing bit 2 of the status resister, you find if the result of the last operation was zero or not.

3. ### Markd77 Senior Member

Sep 7, 2009
2,803
594
You should find that because 3 XOR 3 = 0 that it should skip to the goto next1 instruction.

You will probably find it easier to write btfss STATUS, Z (Z and C are defined in an INC file).

A few instructions don't affect the Zero flag, (SWAPF, RLF, DECFSZ, etc) - there is a table in the datasheets that lists the flags affected.

Last edited: Mar 11, 2010
4. ### daredavel Thread Starter Member

Feb 22, 2010
32
0
thank you sir! it will go to 'next1' sir? not in 'next'? because the result was 0..so it will continue to the next line? if the result is 1, it will go to 'next1'? im kinda confuse..

Last edited: Mar 11, 2010