Stupid Zero Flag question

Thread Starter

daredavel

Joined Feb 22, 2010
32
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!!
 

rjenkins

Joined Nov 6, 2005
1,013
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)

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

Markd77

Joined Sep 7, 2009
2,806
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:

Thread Starter

daredavel

Joined Feb 22, 2010
32
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:
Top