The 8 bits in the Z80's flag register F are, from b7 to b0: S (sign) Set if the result is negative (most significant bit set) Z (zero) Set if the result is zero F5 Undefined and not emulated H (half carry) Set if there is a carry/borrow between the low and high nybbles F3 Undefined and not emulated PV (parity/overflow) Set if the result has even parity (logical operations) Set if signed overflow has occurred (arithmetic operations) N (add/subtract) Set if the operation is a subtraction C (carry) Set if there is a carry/borrow out (arithmetic operations) Set according to the bit moved out (logical operations) The table below shows the effect of all instructions on F. ? indicates the effect is undefined. * indicates the effect is non-standard (see the notes). 0 indicates the flag is reset. 1 indicates the flag is set. - indicates the flag is not affected. S,Z,H,P,V,N,C indicate the flag is set as above. r refers to any 8-bit quantity appropriate for that instruction. s refers to any 16-bit quantity appropriate for that instruction. Instruction Flags Notes =========== ===== ===== ADD/ADC/SUB/SBC/CP r SZ?H?VNC CP is just SUB with the result thrown away INC/DEC r SZ?H?VN- ADD s --?*?-0C H from MSB ADC/SBC s SZ?*?VNC H from MSB INC/DEC s --?-?--- AND r SZ?1?P00 OR/XOR r SZ?0?P00 RLCA/RLA/RRCA/RRA --?0?-0C RLC/RL/RRC/RR r SZ?0?P0C SLA/SLL/SRA/SRL r SZ?0?P0C SLL is like SLA except b0 gets set RRD/RLD SZ?0?P0- Flags set on result in A BIT n,r *Z?1?*0- PV as Z, S set only if n=7 and b7 of r set CCF --?*?-0* C=1-C, H as old C SCF --?0?-01 CPL --?1?-1- NEG SZ?H?V1C A=0-A (Zaks gets C wrong) DAA SZ?*?P-* H from internal correction, C for cascade BCD LD A,R/LD A,I SZ?0?*0- PV as IFF2 [yaze doesn't affect F?] LDI/LDIR/LDD/LDIR --?0?*0- PV set if BC<>0 [Zilog summ says S,Z mod?] CPI/CPIR/CPD/CPDR SZ?H?*1- PV set if BC<>0, other flags from last CP IN r,(C) SZ?0?P0- INI/INIR/IND/INDR ?*????1- Z set if B=0, B is decremented after IN [Zilog detail says N affected and C undef?] OUTI/OTIR/OUTD/OTDR ?*????1- Z set if B=0, B is decremented before OUT [Zilog detail says N affected and C undef?] OUT (C),r/OUT (n),A --?-?--- [Zilog detail says affect F?] All others --?-?--- Except for POP AF and EX AF,AF', of course... 1996-02-28