Page 353 - Programming Microcontrollers in C
P. 353
338 Chapter 6 Large Microcontrollers
pulm d ; restore old xk
tbxk
ais #4 ; fix the stack
ted ; data to be returned
rts ; return
.public _circular_conv
.end
Listing 6-10: Circular Convolution Routine In Assembly Language
Variable names get lost from the program when executing an
assembly language program called from C. Therefore, when a func
tion is entered, the names of the variables are replaced by offsets
from a table saved by the compiler. Programming functions without
the aid labels and variable names requires careful attention to the
details of stacking and unstacking these data. It is recommended that
when a program is to be prepared, an abbreviated version like the
function dot_product( ) above—which will guide the program
mer in setting up the variable locations in memory—be written. In
the above routine, the offset OFST was not used, and the various
offsets were assigned names that correspond to the variables. This
approach makes it easier to understand what the program is doing
and easier to write the code correctly.
It is important that the contents of the XK register be restored to its
initial value when a function call is returned to the calling program.
The content of the X and D registers is saved on the stack and the value
or XK is then saved. The contents of the stack are placed in the X
register, and this register is incremented by two so that it will point to
the last data pushed on the stack. The M register is cleared, and the
parameter ylen is moved into the E register. This value is used with
the rmac instruction to tell how many times the mac instruction is to
be repeated. The value of xlen is the length of the buffer that contains
input data. This buffer is fed circularly so that when the calculation
reaches the last entry in the buffer the pointer into the buffer will be
returned to the top of the buffer to get its next entry. The length xlen
is the number of entries in the buffer, but the length for the calculation
must be the number of bytes in the buffer. Therefore, the value of
xlen must be doubled prior to the creation of a mask to be used in
XMASK. In this case, XMASK value is calculated, and YMASK which is
stored as the B register content of the D register is made zero. There