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

42                                             Chapter 2 The Instruction Set





























                     Figure 2.15. Program Segment for Insertion of Some Bits

            The remaining shifts and rotates (e.g., LSR, LSL, ROR, ROL) are easily
        understood by looking at Figure 2.12. The rotate instructions are used with multiple-byte
        arithmetic operations such as division and multiplication. Edit instructions are generally
        used to rearrange bits. For example, Figure 2.14 swaps the nibbles in accumulator A.
            In a slightly more interesting problem, we insert the three low-order bits of the byte
        in $854 into bits 9 to 7 of the 16-bit word at location $856. This program in Figure
        2.15 illustrates the use of logical instructions to remove unwanted bits and to combine
        bits and edit instructions to move bits into the desired bit positions. A program segment
        like this is used in C structs using bit fields and is commonly used in inserting bits
        into I/O ports that do not line up with whole bytes or whole 16-bit words.
            In this example, observe that all logical and many edit instructions are performed on
        8-bit operands in each instruction. However, instructions are so designed that pairs of
        instructions, on accumulator A and accumulator B, effectively work on accumulator D,


        2.5 Control Instructions

        The next class of instructions, the control instructions, are those that affect the program
        counter PC. After the MOVE class, this class composes the most-often-used
        instructions. Control instructions are divided into conditional branching instructions and
        other control instructions. We discuss conditional branching first and then the others.
            The BRA instruction loads the PC with a new value, using relative addressing
        discussed in §3.3. It adds the last byte of its instruction, called the offset, to the PC.
        Branch statements have "long" branch counterparts where each mnemonic is prefaced
        with an L, such as LBRA, and the offset is two bytes, enabling the programmer to add
        larger values to the PC, to branch to locations further from the instruction.
   60   61   62   63   64   65   66   67   68   69   70