Z-80 Programming Reference; Carry Flag (C); Add/Subtract Flag (N) / The Zero Flag (Z); 4·1 Z-80 Status Indicators (Flags) - Sharp mz-800 Technical Reference And User's Manual

Hide thumbs Also See for mz-800:
Table of Contents

Advertisement

4
Z-80 Programming reference
4-1 Z-80 Status indicators (Flags)
The flag register (F and F') supplies information to the user regarding the status of the Z80 at any given t
~t
'tr
bit positions for each flag is shown below:
7
6
5
4
3
2
0
s
z
X
H
X I P!VI N
c
where:
c
=
Carry Flag
N
=
Add/Subtract Flag
P!V
=
Parity/Overflow Flag
H
Half-Carry Flag
z
Zero Flag
s
Sign Flag
X
Not Used
Each of the two Z-80 Flag Registers contains 6 bits of status information which are set or reset by G',
operations. (Bits 3 and 5 are not used.) Four of these bits are testable (C, P/V, Z and S) for use with cond1t
~'"-•
jump, call or return instructions. Two flags are not testable (H, N) and are used for BCD arithmetic.
Carry Flag (C)
The carry bit is set or reset depending on the operation being performed. For' ADD' instructions that genera!.!
1
carry and 'SUBTRACT' instructions that generate no borrow, the Carry Flag will be set. The Carry Flag 11
'f~->'
by an ADD that does not generate a carry and a 'SUBTRACT' that generates a borrow. This saved carry
facil,ta~r.
software routines for extended precision arithmetic. Also, the 'DAA' instruction will set the Carry Flag
i!
·~.
conditions for making the decimal adjustment are met.
For instructions RLA, RRA, RLS and RRS, the carry bit is used as a link between the LSB and MSB for !'"•
register or memory location. During instructions R LCA, R LC s and SLA s, the carry contains the last
vl'c1
shifted out of bit 7 of any register or memory location. During instructions R RCA, R RC s, SRA sand SRL .
the carry contains the last value shifted out of bit 0 of any register or memory location.
For the logical instructions AND s, OR sand XOR s, the carry will be reset.
The Carry Flag can also be set (SCF) and complemented (CCF).
Add/Subtract Flag (N)
This flag is used by the decimal adjust accumulator instruction (DAA) to distinguish between 'ADD" ,...
'SUBTRJ\CT' instructions. For all 'ADD' instructions, N will be set to an '0'. For all 'SUBTRACT' instructiOPI '.
will be set to a '1 '.
The Zero Flag (Z)
The Zero Flag (Z) is set or reset if the result generated by the execution of certain instructions is a zero.
For 8-bit arithmetic and logical operations, the Z flag will be set to a '1' if the resulting byte in the Accumula::--
is zero. If the byte is not zero, the Z flag is reset to '0'.
For compare (search) instructions, the Z flag will be set to a '1' if a comparison is found between the value in
1
'
1
Accumulator and the memory location pointed to by the contents of the register pair HL.
When testing a bit in a register or memory location, the Z flag will contain the complemented state of :'"<
indicated bit (see Bit b,s).
When inputting or outputting a byte between a memory location and an 1/0 device (IN I, IND, OUT I and OUL
if the result of B-1 is zero, the Z flag is set, otherwise it is reset. Also for byte inputs from 1/0 devices-"·
IN r, (C), the Z flag is set to indicate a zero byte input.
138

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents