Page 36 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 36
1.3 A Few Instructions And Some Simple Programs I3
Figure 1.8. Program for 16-Bit Addition
In the program segment above, the instruction ADCA $812 adds the contents of A
with the contents of location $812 and the C condition code bit, putting the result in A.
At that point in the sequence, this instruction adds the two higher-order bytes of the two
numbers together with the carry generated from adding the two lower-order bytes
previously. This is, of course, exactly what we would do by hand, as seen in Figure 1.7.
Note that we can put this sequence in any 19 consecutive bytes of memory as long as the
19 bytes do not overlap with data locations $810 through $815. Finally, the notation
A:B is used for putting the accumulator A in tandem with B or concatenating A with B.
This concatenation is just the double accumulator D. We could also have used just one
accumulator with the following instruction sequence.
In this new sequence, the load and store instructions do not affect the carry bit C.
(See the CPU12RG/D manual Instruction Set Summary. We will understand why
instructions do not affect C as we look at more examples.) Thus, when the instruction
ADCA $ 812 is performed, C has been determined by the ADDB $ 813 instruction.
The two programs above were equally acceptable. However, we want to discuss
guidelines to writing good programs early in the book, so that you can be aware of them
to know what we are expecting for answers to problems and so that you can develop a
good programming style. A good program is shorter and faster and is generally clearer
than a bad program that solves the same problem. Unfortunately, the fastest program is
Figure 1.9. Alternative Program for 16-Bit Addition