67/317
4 - Architecture of the ST7 core
H bit
This bit is a similar to the
C
bit, since it is set when a carry occurs. This time, it is the carry be-
tween the two nibbles of a byte. A byte is composed of two four-bit groups called nibbles. The
H
bit is set whenever an arithmetic instruction produces a carry between bit 3 and bit 4 of the
accumulator.
This half-carry is used when performing decimal arithmetic. In this case, each nibble contains
a BCD digit, so that the bit pattern for 23 in decimal is 00100011, and reads also
23
in hexa-
decimal. This kind of coding is called Packed BCD. To correctly add two packed BCD num-
bers, some correction is necessary, which is made possible by the H bit. Several cases must
then be considered:
First case: adding the numbers 23 and 52.
Once coded in packed BCD, they read
23h
and
52h
. If we add these numbers, we expect to
find 75. Actually, if we perform the ADD instructions on these numbers, we find
75h
, as the
rules for adding two binary numbers imply. We directly get the right answer in packed BCD.
No half-carry has occurred.
Second case: adding the numbers 23 and 59.
Once coded in packed BCD, they read
23h
and
59h
. If we add these numbers, we expect to
find 82. But if we perform the ADD instructions on these numbers, we find
7Ch
, as the rules
for adding two binary numbers imply. This is because
3
+
9
=
C
in hexadecimal.
C
is not an
acceptable digit in BCD. However, it is easy to see that if we add 6 to the total (the difference
between 15 and 9), we get
82h
, which is also the right answer in packed BCD. No half-carry
has occurred.
Third case: adding 28 and 59.
We expect to get 87. Once added as above, we get
81h
. This time, a half-carry occurred.
This indicates that we must add 6 to the result, giving
87h
, which is the right answer.
To summarize, if the addition of two packed BCD numbers gives no half-carry and if the least-
significant nibble is less than
0Ah
, the result is correct as it is. Otherwise, adding 6 will correct
the result.
The same thing applies for the most-significant nibble: if it has a value less than
A
, and there
is no carry, the result is correct; otherwise, adding
60h
will correct the result.
Complicated as it might seem, the handling of packed BCD avoids having to convert numbers
back and forth between binary and decimal, although this may be easier in some cases.
4.2.2.3 Index registers (X and Y)
The index registers are meant to hold addresses, unlike the accumulator which is meant to
hold data. The value stored in
X
or
Y
is involved in the effective address calculation in some ad-
dressing modes. The availability of two index registers allows for calculating and managing
Содержание ST7 Series
Страница 1: ...ST7 8 BIT MCU FAMILY USER GUIDE JANUARY 1999 1 ...
Страница 238: ...238 317 8 C Language and the C Compiler 08 Burn bmp Then use the EPROMer programmer software as described in Chapter 7 ...
Страница 289: ...289 317 10 Second Application a Sailing Computer 10 befor Bs Rw Vw VMG AlphaR AlphaV Before the wind ...