Page 344 - Programming Microcontrollers in C
P. 344

Digital Signal Processor Operations   329

                   void dot_product(char length, int* xdata, int* ydata)
                   {
                          int i,*xp, *yp;
                          xp=xdata;
                          yp=ydata;
                          i=length;
                   }
                              Listing 6-8: Sample Parameter Handling Function
                              The compiled version of the above function is shown below. The
                          first important instruction is the .even assembly directive that causes
                          the code to follow to start on an even boundary. Code must be started
                          at an even address. Note in the program above that three parameters
                          are passed to the function. After the contents of the X and the D
                          registers are saved, the stack pointer is decremented by 6 to provide
                          space for the variables i, *xp, and *yp. The two pointer param­
                          eters require 16 bits each, and the character parameter needs only 8
                          bits. The program, in favor of greater speed, will store the variable i
                          in a 16-bit location even though i is only 8 bits wide. At this time,
                          the value contained in the stack pointer is transferred into the X reg­
                          ister. During this transfer, the value will be automatically incremented
                          by two so that the contents of the X register will be pointed to the last
                          value stored on the stack rather than to the next empty location on
                          the stack as is found in the stack pointer.
                   1  ; Compilateur C pour MC68HC16 (COSMIC-France)
                   2  .include “macro.h16”
                   3  .list +
                   4  .psect _text
                   5  ; 1 void dot_product(char length, int* xdata, int* ydata)
                   6  ; 2 {
                   7  .even
                   8  _dot_product:
                   9  pshm x,d
                   10 ais #-6
                   11 tsx
                   12 .set OFST=6
                   13 ; 3 int i,*xp, *yp;
                   14 ; 4
                   15 ; 5 xp=xdata;
                   16 ldd OFST+8,x
                   17 std OFST-4,x
                   18 ; 6 yp=ydata;
                   19 ldd OFST+10,x
   339   340   341   342   343   344   345   346   347   348   349