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

64                                             Chapter 3 Addressing Modes


         loads the number contained in location $3012 + $843 = $3855 into accumulator A. The
        post byte for this 16-bit offset mode (see Figure 3.2) has ones in bits 7 to 5, the index
         register in bits 4 and 3 (00 is X, 01 is Y, 10 is SP, and 11 is PC), and 010 in bits 2 to
        0. The machine code is given by










         where $A6 is the opcode byte for any index option with LDAA, $E2 is the the post
        byte, and $3012 is the 16-bit two's-complement offset. The saved offset is added to the
         index register to get the effective address, as illustrated by Figure 3.4.
            In short, addresses requiring several accesses are kept in index registers, if possible,
         and utilize the more efficient index addressing. Shorter offsets produce more efficient
         programs and can be used if the index register value is close to the effective addresses that
         will be used. But while negative offsets are mechanically as usable as positive offsets to
        more often use shorter offsets, positive offsets are often preferred for clarity.
            The 5-, 9-, and 16-bit offset index addressing modes are useful for reading data out of
         a vector. Suppose a 10-element vector of 8-bit items has element 0 at $843, element 1 at
         $844, element 2 at $845, and so on. Then if X has $843, then

                                        LDAA 2,X
        puts element 2 into accumulator A. Suppose now that a 10-element vector of 8-bit items
        has element 0 at $872, element 1 at $873, element 2 at $874, and so on. Then if X has
         $872, this instruction still gets element 2 out of the vector. This instruction uses the
        efficient 5-bit offset mode. The following instruction gets element i from the vector
        beginning at $843 into accumulator A, where the vector index i is in index register X:
                                      LDAA $843,X
        This instruction uses the less efficient 16-bit offset mode, but it lets the variable index
        be in the X index register.
            Index registers can be either autoincremented or autodecremented before or after
         being used in effective address calculations. It is denoted by a delta value between 1 and













                         Figure 3.5. Autoincrement Address Calculation
   82   83   84   85   86   87   88   89   90   91   92