<< Chapter < Page | Chapter >> Page > |
TI's linear assembly language enables you to write an assembly-like programs without worrying about register usage, pipelining, delayslots, etc. The assembler optimizer program reads the linear assembly code to figure out the algorithm, and then it producesan optimized list of assembly code to perform the operations. The linear assembly programming lets you:
The linear assembly files have
.sa
extensions. When you have a linear assembly file in your
Code Composer Studio project, the assembly optimizer isinvoked automatically to generate optimized actual
assembly routine. You can consider the linear assemblylanguage as a tool to describe algorithms. To effectively
convey the intent of the programmer to the assemblyoptimizer for proper optimization, there are quite a few
extra directives in linear assembly.
The following is an example of C callable linear assembly routine that computes the dot product of two vectors. Itimplements a C function
short dotp(short* a, short* x, int count);
If
a[]
and
x[]
are two length-40 vectors, the C function call has the
form
short a[];
short x[];
short z;
...
...
z = dotp(a,x,40);
...
(see below how the arguments are passed and the pointers are used.) In the following, you learn various assembler directivesused below and how the optimized assembly code is generated by the assembler optimizer.
_dotp: .cproc ap,xp,cnt
.reg a,x,prod,y
MVK 40,cnt
loop: .trip 40
LDH *ap++,a
LDH *ax++,x
MPY a,x,prod
ADD y,prod,y
SUB cnt,1,cnt
[cnt] B loop
.return y
.endproc
The
.cproc
directive starts a C callable
procedure. It must be used with
.endproc
to
end a C procedure.
_dotp:
is the label used
to name the procedure. By using
.cproc
to
start the procedure, the assembly optimizer performs someoperations automatically in a
.cproc
region
in order to make the function conform to the C callingconventions and to C register usage convention. The
following optional variables (
ap,xp,cnt
above) represent function parameters. The variable entries
are very similar to parameters declared in a C function.
The arguments to the
.cproc
directive can be
either machine-register names or symbolic names. Whenregister names are specified, its position in the argument
list must correspond to the argument passing conventionsfor C. For example, the first argument in C function must
be register A4. When symbolic names are specified, theassembly optimizer ensures proper allocation and
initialization (if necessary) of registers at thebeginning of the procedure. To represent a 40-bit
argument, a register pair can be specified as anargument. In this lab, however, we only use 32bit values
as arguments.
The
.reg
directive allows you to use descriptive
names for values that will be stored in registers. It isvalid only within procedures only.
The
.return
directive functionality is
equivalent to the return statement in C code. It placesthe optional argument in the appropriate register for a
return value as per the C calling conventions. If noargument is specified, no value is returned, similar to a
void
function in C code. To perform a
conditional
.return
, you can simply put
conditional branch around a
.return
as:
[!cc] B around
.return
around:
The
.trip
directive specifies the value of
the trip count. The
trip count indicates how many times a loop will iterate. By giving
this extra information to the assembler optimizer, abetter optimization is achieved for loops. The label
preceding
.trip
directive represents the
beginning of the loop. This is a required parameter.
For more information on writing C callable linear assembly procedure, refer to TMS320C6x Optimizing C Compiler User's Guide . For C6x assembly instructions, refer to TMS320C62x/C67x CPU and Instruction Set Reference Guide .
Write a C callable FIR filtering routine in linear assembly. When using different optimization levels, what is the numberof clock cycles of each FIR filtering?
Notification Switch
Would you like to follow the 'Finite impulse response' conversation and receive update notifications?