Page 51 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 51
28 Chapter 2 The Instruction Set
At the conclusion of the chapter, you will have all the tools needed to write useful
programs for the 6812, in machine code. You should be able to write programs on the
order of 20 instructions long, and you should be able to write the machine code for these
programs. If you have a laboratory parallel to a course that uses this book, you should be
able to enter these programs, execute them, debug them, and, using this hands-on
experience, you should begin to understand computing.
2.1 Move Instructions
Behold the humble move instructions, for they labor to carry the data for the most
elegant instructions. You might get excited when you find that this computer has a fairly
fancy instruction like multiply, or you might be disappointed that it does not have
floating-point instructions like the ones most big machines sport. Studies have shown
that, depending on the kind of application program examined, between 25 and 40% of the
instructions were move instructions, while only 0.1% of the instructions were
multiplies. As you begin to understand computing, you will learn to highly regard these
humble move instructions and to use them well.
Move instructions essentially move one or two bytes from memory to a register (or
vice versa) or between registers or memory locations. The two aspects of these
instructions that give most readers some problems are the setting of condition codes and
the allowable addressing modes. We shall take some care with the setting of condition
codes in this chapter and the allowable addressing modes in the next chapter.
The two simplest instructions from the move class are the load and store
instructions. These have already been examined for accumulators A, B, and D; they also
may be used with index registers like X. For example, in the load instruction
LDX 2062
the high byte of X is taken from location 2062 while the low byte of X is taken from
location 2063. An exactly parallel situation holds for the store instruction
STX 2337
where the high byte of X is put into location 2337 while the low byte of X is put into
location 2338. In addition to X, there are load and store instructions for index register Y
and stack pointer S. They work exactly as described for D.
The TST and CLR instructions are two more examples in the move class of
instructions of the 6812. The clear instruction CLR is used to initialize the accumulators
or memory locations with the value zero. As such, CLRA can replace instructions such
as LDAA #0 in the sequence in Figure 2.1. Further, the two instructions in Figure 2.1
can be replaced by the single instruction CLR 2090.
Figure 2.1. A Program Segment to Clear a Byte