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

3.5 Examples                                                         77















                    Figure 3.18. Program Segment to Move a Block of Memory
        overflow; that is, the result can be expressed with an 8-bit two's-complement number.
        Note that accumulator B is initially loaded with the number of times that the loop is to
        be executed. This loop counter (accumulator B in this case) is decremented by DBNE ,
        which branches back to the location L if the (B) is greater than zero after it is
        decremented. The loop from location L to the DBNE instruction is repeated N times,
        where N is the initial value in accumulator B.
            In the program in Figure 3.19, register A is used to accumulate the result, register B
        holds the number of remaining bytes to be added, and the index register X contains the
        address that points to the next byte to be added.
            We extend the multiply-and-accumulate example of §2.7 to evaluate the expression:
        2 i = 0 Bi * Q , where a vector of five signed 16-bit numbers Bj are at $914, and a
        vector of five signed 16-bit numbers Q is at $9IE. This expression is called the inner
        product of the vectors B and C. The two vectors B and C can have as many elements as
        you want, but the two vectors have the same number of elements. It is widely used in
        signal processing and data compression. See Figure 3.20. Note that EM ACS only uses
        pointer addressing, so the index registers X and Y must be moved using LEA
        instructions in order to pick up the elements Bi and Q. This procedure is very similar to
        the WAV instruction but is for 16-bit elements while WAV is for 8-bit elements.
            This section illustrates several examples of the great value of the synergetic
        combination of autoincrement index addressing and counting using the DBNE instruction.
        The combination of accumulator index addressing and counting using the DBNE
        instruction, whose counter register is the accumulator used with the index, is also widely
        used. We seern to run into such a combination in every other program that we write.
















                     Figure 3.19. Program Segment to Add Vector Elements
   95   96   97   98   99   100   101   102   103   104   105