66/317
4 - Architecture of the ST7 core
04-ccreg
The leftmost three bits, indicated as ones, are not used. When read, they yield ones.
C bit
The
C
bit is the carry that is generated by an addition or subtraction. When adding 16-bit num-
bers, for example, we first add the two least-significant bytes together, then the most signifi-
cant ones. If the result of the first addition yields a result greater than 255, it cannot fit in a byte.
For example, adding 1200 and 6230 in decimal yields 7430. In hexadecimal notation, this is:
4B0
+
1856
=
1D06
Adding these numbers is performed in two steps. First,
B0
is added to
56
, yielding
06
with a
carry of one. Then,
4
is added to
18
, yielding
1C
, and with the addition of the carry we get
1D
.
The role of the
C
bit of the Condition Code register is to remember that carry between the two
additions. The first addition is performed using the
ADD
instruction, and the second must use
the
ADC
instruction (add with carry) that increments the result of the addition if the
C
bit is a one.
The instructions that affect the carry bit are mainly addition and subtraction, the shift and ro-
tate instructions, and of course instructions that directly affect the
CC
register.
The instructions that use the
C
bit are
ADC
and
SBC
(subtract with carry), the rotate instructions,
and some conditional jump instructions.
Z bit
This bit is set to one to reflect the fact that a value is zero, whenever the accumulator is loaded
or after any arithmetic or logical operation. If the value is not zero, the
Z
bit is cleared. The in-
structions that affect or use the
Z
bit are the same as those for the
C
bit.
N bit
This bit is set to one to reflect the fact that a value is negative, in two’s complement notation.
A negative number has its most significant bit set to one; so the
N
bit reflects the most signifi-
cant bit whenever the accumulator is loaded or after any arithmetic or logical operation. If the
value is positive, the bit
N
is cleared. The value zero is considered positive. The instructions
that affect or use the
N
bit are the same as those for the
C
bit.
I bit
This bit is the global interrupt mask. When this bit is set, all interrupts are ignored. However, if
an interrupt request is present, clearing the
I
bit immediately triggers an interrupt.
Condition code register
1
1
1
1
H
I
N
Z
C