Page 352 - Programming Microcontrollers in C
P. 352
Digital Signal Processor Operations 337
altered by any function call. Therefore, it is necessary to save the
contents of the X register prior to altering this register.
; int circular_conv(char xlen, int* xdata, char ylen, int* ydata)
.even
.set xlen=5
.set xk=11
.set xdata=12
.set ylen=15
.set yk=17
.set ydata=18
_circular_conv:
pshm x,d
txK ; save old xk
pshm d
tsx
clrm ; clear the m register
clra ; put ylen into e register
ldab ylen,x ; ylen
addb #-1 ; decrement count to get correct
tde ; number of iterations
ldaa xlen,x ; xlen is the circular part
asla ; of the convolution. Create
coma ; a mask that is the compliment
clrb ; of twice the length.
tdmsk ; put xlen in XMASK
ldab yk,x
tbyk
ldy ydata,x ; ydata with yk extension
pshm x ; save x
ldab xk,x
tbxk
ldx xdata,x ; xdata with the xk extension
ldhi ; load H and I registers for mpy
rmac 2,2 ; do rmac ylen times
tmer ; send result to e and then
pulm x ; restore x
ldx 2,x ; restore it to its original value