Hardware Reference
In-Depth Information
$
$
1
8
9
1
6
9
F
4
7
B
5
8
D
+
$
The result is $11FBD, a 17-bit number, which is too large to fit into the 16-bit double
accumulator D. When the HCS12 executes these two instructions, the lower 16 bits of the
answer, $1FBD, are placed in double accumulator D. This part of the answer is called sum .
The leftmost bit is called a carry. A carry of 1 following an addition instruction sets the C fl ag
of the CCR register to 1. A carry of 0 following an addition clears the C fl ag to 0. This applies
to both 8-bit and 16-bit additions for the HCS12. For example, execution of the following two
instructions
ldd #$1245
addd #$4581
will clear the C fl ag to 0 because the carry resulting from this addition is 0. In summary,
If the addition produces a carry of 1, the carry flag is set to 1.
If the addition produces a carry of 0, the carry flag is cleared to 0.
2.5.2 Multiprecision Addition
For a 16-bit microcontroller like the HCS12, multiprecision addition is the addition of
numbers that are larger than 16 bits. To add the hex number $1A598183 to $76548290, the
HCS12 has to perform multiprecision addition.
1
1
7
9
1
9
4
E
1
1
2
4
3
0
3
Multiprecision addition is performed 1 byte at a time, beginning with the least signifi cant byte.
The HCS12 does allow us to add 16-bit numbers at a time because it has the addd instruc-
tion. The following two instructions can be used to add the least signifi cant 16-bit numbers
together:
ldd #$8183
addd #$8290
Since the sum of the most signifi cant digit is greater than 16, it generates a carry that must
be added to the next more signifi cant digit, causing the C fl ag to be set to 1. The contents of
double accumulator D must be saved before the higher bytes are added. Here the 2 bytes are
saved at $1002,$1003.
std $1002
When the second most signifi cant bytes are added, the carry from the lower byte must be added
in order to obtain the correct sum. In other words, we need an “add with carry” instruction.
There are two versions of this instruction: the adca instruction for accumulator A and the adcb
instruction for accumulator B. The instructions for adding the second signifi cant bytes are
ldaa #$59
adca #$54
We need also to save the second most signifi cant byte of the result at $1001 with the following
instruction:
$
$
$
A
6
0
5
5
A
8
8
0
8
9
1
+
staa
$1001
 
 
Search WWH ::




Custom Search