Page 57 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 57

34                                            Chapter 2 The Instruction Set

         2.2 Arithmetic Instructions


         The computer is often used to compute numerical data, as the name implies, or to keep
         books or control machinery. These operations need arithmetic instructions, which we
         now study. However, you must recall that computers are designed and programs are
         written to enhance static or dynamic efficiency. Rather than have the four basic
         arithmetic instructions that you learned in grade school—-add, subtract, multiply, and
         divide—computers have the instructions that occur most often in programs. Rather than
         having the sophisticated square root as an instruction, for instance, we will see the often-
         used increment instruction in a computer. Let us look at them. See Table 2.4.
            We have already discussed the add instructions: ADCA, ADCB,ADDA, ADDB, and
         ADDD. The corresponding subtraction instructions, SBCA, SBCB, SUBA, SUBB, and
         SUBD, are the obvious counterparts of add instructions, where the carry condition code
         bit holds the borrow. However, 16-bit add and subtract instructions with carry, ADCD and
         SBCD, are missing; multiple-byte arithmetic must be done one byte at a time rather than
         two bytes at a time. Comparisons are normally made by subtracting two numbers and
         checking if the result is zero, negative, positive, or a combination of these. But using
         the subtract instruction to compare a fixed number against many numbers requires that
         the fixed number has to be reloaded in the register each time the subtraction is performed.
         To streamline this process, compare instructions are included that do not change the
         contents of the register used. These compare instructions are used to compare the
         contents of registers A, B, D, X, Y, and SP with the contents of memory locations in
         order to give values to the condition code bits C, V, N, and Z. Finally, note that DEC,
         INC, and NEC are provided for often-used special cases of add and subtract instructions,
         to improve efficiency.

                      Table 2.4. Add Instructions Using an Effective Address
   52   53   54   55   56   57   58   59   60   61   62