Digital Signal Processing Reference
In-Depth Information
//
Dotp4clasm.c
Multiplies two arrays using C calling linear ASM func
short dotp4clasmfunc(short *a,short *b,short ncount); //prototype
#include <stdio.h> //for printing statement
#include "dotp4.h" //arrays of data values
#define count 4 //number of data values
short x[count] = {x_array};
//declare 1st array
short y[count] = {y_array};
//declare 2nd array
volatile int result = 0;
//result
main()
{
result = dotp4clasmfunc(x,y,count); //call linear ASM func
printf("result = %d decimal \n", result); //print result
}
FIGURE 3.21.
C program calling a linear ASM function to find the sum of products
(
dotp4clasm.c
).
;
Dotp4clasmfunc.sa
Linear assembly function to multiply two arrays
.ref _dotp4clasmfunc ;ASM func called from C
_dotp4clasmfunc: .cproc ap,bp,count ;start section linear ASM
.reg a,b,prod,sum ;asm optimizer directive
zero sum ;init sum of products
loop: ldh *ap++,a ;pointer to 1st array->a
ldh *bp++,b ;pointer to 2nd array->b
mpy a,b,prod ;product = a*b
add prod,sum,sum ;sum of products -->sum
sub count,1,count ;decrement counter
[count] b loop ;loop back if count # 0
.return sum
;return sum as result
.endproc
;end linear ASM function
FIGURE 3.22.
Linear ASM function called from C to find the sum of products
(
dotp4clasmfunc.sa
).
Functional units are optional as in an assembly-coded program. Registers
a
,
b
,
prod
, and
sum
are defined by the linear assembler directive
.
reg
. The addresses
of the two arrays
x
and
y
and the size of the array (count) are passed to the linear
assembly function through the registers
ap
,
bp
, and
count
. Both
ap
and
bp
are
registers used as pointers, as in C code. The instruction field is seen to be as in an
assembly-coded program, and the subsequent field uses a syntax as in C program-
ming. For example, the instruction
loop: ldh *ap++,a
(the first time through the loop section of code) loads the content in memory, whose
address is specified by register
ap
, into register
a
. Then the pointer register
ap
is
postincremented to point to the next higher memory address, pointing at the
Search WWH ::
Custom Search