Z8 Microcontrollers
Instruction Set ZiLOG
12-4 UM001601-0803
12.2.1 Carry Flag (C)
The Carry Flag is set to 1 whenever the result of an arithmetic
operation generates a carry or a borrow the high order bit 7. Oth
-
erwise, 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 Instruction 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 re-
sult following an arithmetic, logical, Rotate, or Shift operation.
When performing arithmetic operations on signed numbers, bi-
nary two’s-complement notation is used to represent and process
information. A positive number is identified 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 significant 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 Over-
flow Flag is set to 1 when the result is greater than the maximum
possible number (>127) or less than the minimum possible num
-
ber (<–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 instruction was
last executed so that the subsequent Decimal Adjust (DA) oper
-
ation can function properly. Normally, the Decimal Adjust Flag
cannot be used as a test condition.
After a subtraction, the Decimal Adjust Flag is set to 1. Follow-
ing 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 generates a
carry bit 3 (Overflow) or a subtraction generates a borrow bit 3.
The Half Carry Flag is used by the Decimal Adjust (DA) instruc
-
tion to convert the binary result of a previous addition or subtrac-
tion 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.