Z8 Microcontrollers
Instruction Set
ZiLOG
12-4
UM001600-Z8X0599
12.2.1 Carry Flag (C)
The Carry Flag is set to 1 whenever the result of an arith-
metic operation generates a carry or a borrow the high or-
der bit 7. Otherwise, the Carry Flag is cleared to 0.
Following Rotate and Shift instructions, the Carry Flag
contains the last value shifted out of the specified register.
An instruction can set, reset, or complement the Carry
Flag.
IRET may change the value of the Carry Flag when the
Flag Register, saved in the Stack, is restored.
12.2.2 Zero Flag (Z)
For arithmetic and logical operations, the Zero Flag is set
to 1 if the result is zero. Otherwise, the Zero Flag is cleared
to 0.
If the result of testing bits in a register is 00H, the Zero Flag
is set to 1. Otherwise the Zero Flag is cleared to 0.
If the result of a Rotate or Shift operation is 00H, the Zero
Flag is set to 1. Otherwise, the Zero Flag is cleared to 0.
IRET changes the value of the Zero Flag when the Flag
Register saved in the Stack is restored. The WDT Instruc-
tion sets the Zero Flag to a 1.
12.2.3 Sign Flag (S)
The Sign Flag stores the value of the most significant bit of
a result following an arithmetic, logical, Rotate, or Shift op-
eration.
When performing arithmetic operations on signed num-
bers, binary two’s-complement notation is used to repre-
sent and process information. A positive number is identi-
fied by a 0 in the most significant bit position (bit 7);
therefore, the Sign Flag is also 0.
A negative number is identified by a 1 in the most signifi-
cant bit position (bit 7); therefore, the Sign Flag is also 1.
IRET changes the value of the Sign Flag when the Flag
Register saved in the Stack is restored.
12.2.4 Overflow Flag (V)
For signed arithmetic, Rotate, and Shift operations, the
Overflow Flag is set to 1 when the result is greater than the
maximum possible number (>127) or less than the mini-
mum possible number (<–128) that can be represented in
two’s-complement form. The Overflow Flag is set to 0 if no
overflow occurs.
Following logical operations the Overflow Flag is set to 0.
IRET changes the value of the Overflow Flag when the
Flag Register saved in the Stack is restored.
12.2.5 Decimal Adjust Flag (D)
The Decimal Adjust Flag is used for BCD arithmetic. Since
the algorithm for correcting BCD operations is different for
addition and subtraction, this flag specifies what type of in-
struction was last executed so that the subsequent Deci-
mal Adjust (DA) operation can function properly. Normally,
the Decimal Adjust Flag cannot be used as a test condi-
tion.
After a subtraction, the Decimal Adjust Flag is set to 1. Fol-
lowing an addition it is cleared to 0.
IRET changes the value of the Decimal Adjust Flag when
the Flag Register saved in the Stack is restored.
12.2.6 Half Carry Flag (H)
The Half Carry Flag is set to 1 whenever an addition gen-
erates a carry bit 3 (Overflow) or a subtraction generates a
borrow bit 3. The Half Carry Flag is used by the Decimal
Adjust (DA) instruction to convert the binary result of a pre-
vious addition or subtraction into the correct decimal
(BCD) result. As in the case of the Decimal Adjust Flag, the
user does not normally access this flag.
IRET changes the value of the Half Carry Flag when the
Flag Register saved in the Stack is restored.