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

366                                       Chapter 12 Other Microcontrollers


            Let us now look at the overused inner product subroutine, passing the parameters in
         the in-line argument list by value, in Figure 12.10. Although this method of passing
         parameters is not the best for the 68300 series because it has plenty of registers to pass
         parameters by registers, it illustrates the use of data and address registers and is used by C
         and C++. The LINK and UNLINK instructions are generally used to duplicate the stack
         pointer in another register, commonly A6. Register A6 accesses parameters with positive
         offsets and local variables with negative offsets. But, with an abundance of registers, the
         68300 series can often save intermediate results in registers rather than on the stack, as in
         this example. So this example doesn't use any local variables.
            Whereas we can see that the 68300 series is superior to the microcontrollers
        discussed earlier in this chapter for 16-bit and 32-bit arithmetic, this example shows they
         have a little difficulty in dealing with 8-bit data. The multiply instructions do not have
         an 8-bit by 8-bit multiply such as MULU. W LOCW+1 (A6 ), DO . Moreover, just using
         an instruction like MOVE .B LOCV( A6 ) ,DO to bring in the operand and then using
         MULU. W D1, DO leaves the high-order bits of DO unmodified. Bits 15 to 8 will be used
         in the MULU.W D1,DO instruction. So these bits must be cleared unless they are
         known to be clear already. The instruction CLR. L DO will take care of this. We didn't
        have to worry about such a case in the microcontrollers discussed earlier in this chapter.
        The 68330 series, designed for 16-bit and 32-bit arithmetic, is often no better than the
         6812, 6811, 6808, and 6805 microcontrollers for operating on 8-bit data and may even
        be less efficient for some operations than those microcontrollers are.
            With this short example, some of the flavor of the 68300 series can be seen. The
        machine offers a very large address space, over 16 megabytes, and 17 data and address
         registers. They offer superior performance for 16-bit and 32-bit arithmetic, and a more
        extensive instruction set than the microcontrollers discussed earlier in this chapter.
         However, especially in handling 8-bit data, those microcontrollers discussed earlier in
        this chapter may well exhibit comparable or even superior performance.
           * SUBROUTINE DOTPRD
           * PARAMETERS
          LOCV: EQU 4
          LOCW: EQU 6
          DOTPRD: LIN K     A 6 , 0           ; Allocate no locals; put stack frame in A6
                   C L R . L D 0              ; Clear out high bits of DO
                   CLR. L D 1                 ; Clear out high bits of Dl
                   C L R. L D 2               ; Clear out high bits of D2
                   MOVE. B LOCV (A6), D 0     ; Get V(0)
                   MOVE. B LOCW (A6 ), D1    ; Get W(0)
                   MULU. W Dl, DO            ; Multiply V(0) by W(0), result in DO
                   MOVE.B LOCV+1(A6) / D1 ;GetV(l)
                   MOVE.B LOCW+1 (A6 ) ,D2 ;GetW(l)
                   MULU.W D2,D1              ; Multiply V(l) by W(l)
                   ADD. W D1, DO             ; Dot product into DO
                   UNLINK A6                 ; Deallocate local variables
                   RTS
                      Figure 12.10. A 68300 Series Dot Product Subroutine
   384   385   386   387   388   389   390   391   392   393   394