EasyManua.ls Logo

ST ST7 - Index Registers (X and Y)

ST ST7
317 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
67/317
4 - Architecture of the ST7 core
Hbit
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.
OncecodedinpackedBCD,theyread
23h and 52h.Ifweaddthesenumbers,weexpectto
find 75. Actually, if we perform the ADD instructions on these numbers, we find
75h,asthe
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.
OncecodedinpackedBCD,theyread
23h and 59h.Ifweaddthesenumbers,weexpectto
find 82. But if we perform the ADD instructions on these numbers, we find
7Ch,astherules
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
between15and9),weget
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,andthere
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

Table of Contents

Related product manuals