Decimal adjust accumulator flag, Parity/overflow flag – Zilog Z08470 User Manual

Page 77

Advertising
background image

UM008007-0715

Decimal Adjust Accumulator Flag

Z80 CPU

User Manual

65

Decimal Adjust Accumulator Flag

The Decimal Adjust Accumulator (DAA) instruction uses this flag to distinguish between
ADD and SUBTRACT instructions. For all ADD instructions, N sets to 0. For all SUB-
TRACT instructions, N sets to 1.

Parity/Overflow Flag

The Parity/Overflow (P/V) Flag is set to a specific state depending on the operation being
performed. For arithmetic operations, this flag indicates an overflow condition when the
result in the Accumulator is greater than the maximum possible number (+127) or is less
than the minimum possible number (–128). This overflow condition is determined by
examining the sign bits of the operands.

For addition, operands with different signs never cause overflow. When adding operands
with similar signs and the result contains a different sign, the Overflow Flag is set, as
shown in the following example.

The two numbers added together result in a number that exceeds +127 and the two posi-
tive operands result in a negative number (–95), which is incorrect. The Overflow Flag is
therefore set.

For subtraction, overflow can occur for operands of unalike signs. Operands of alike signs
never cause overflow, as shown in the following example.

The minuend sign has changed from a positive to a negative, resulting in an incorrect dif-
ference; the Overflow Flag is set.

Another method for identifying an overflow is to observe the Carry to and out of the sign
bit. If there is a Carry in and no Carry out, or if there is no Carry in and a Carry out, then
an Overflow has occurred.

This flag is also used with logical operations and rotate instructions to indicate the result-
ing parity is even. The number of 1 bits in a byte are counted. If the total is Odd, ODD par-
ity is flagged (i.e., P = 0). If the total is even, even parity is flagged (i.e., P = 1).

+120

=

0111

1000

ADDEND

+105

=

0110

1001

AUGEND

+225

=

1110

0001

(–95)

SUM

+127

0111

1111

MINUEND

(–) –64

1100

0000

SUBTRAHEND

+191

1011

1111

DIFFERENCE

Advertising
This manual is related to the following products: