ECSE436 Tutorial Assembly and Linear Assembly Laurier Boulianne
L. Boulianne Questions
L. Boulianne Outline Introduction to Assembly Linear Assembly AMR Reading
L. Boulianne TMS320 Assemby Language
L. Boulianne C6000 ISA
L. Boulianne Instruction Packing
L. Boulianne Sample Instructions
L. Boulianne Sample Instruction
L. Boulianne Instruction List
L. Boulianne Instruction List
L. Boulianne C program calling and ASM function
L. Boulianne C program calling and ASM function -Values passed to the assembly functions using registers : A4,B4,A6,B6 and so on -Only registers A1,A2,B0,B1,B2 can be used as conditional registers -B3 contain the return address -A4 is the return value -Need to take into account the NOP
L. Boulianne Linear Assembly To effectively program a DSP using assembly language, you need to do the scheduling by hand! Need to account for the number of clock cycles each functional unit takes, etc… Difficult, so TI has linear assembly –you don’t have to schedule it, the compiler does it for you –can use CPU resources without worrying about scheduling, register allocation, etc…
L. Boulianne What is Linear Assembly ? Enables you write assembly-like programs Do not have to worry about : Register usage Pipelining Delay slots etc.
L. Boulianne What is Linear Assembly ? C code TI Linear Assembly Assembly Efficiency Ease of use
L. Boulianne What is Linear Assembly ? It is a cross between C and Assembly It lets you : use symbolic names forget pipeline issues ignore putting NOPs parallel bars functional units register names more efficiently use CPU resources than C
L. Boulianne Linear Assembly Extension in c is.c Extension in linear assembly is.sa
L. Boulianne Example Dot Product From Chassaing //DOTPclasm.c short dotp4clasmfunc(short *a, short *b, short ncount); #include #define count 4 short x[count] = {0,1,2,3}; short y[count] = {100, -20, 30, -20}; volatile int result = 0; main() { result = dotp4clasmfunc(x,y,count); printf("result = %d decimal \n", result); } Function written in LASM
L. Boulianne.def_dotp4clasmfunc _dotp4clasmfunc:.cproc ap, bp, count.reg a, b, prod, sum zero sum loop:ldh *ap++,a ldh*bp++,b mpya,b,prod addprod,sum,sum subcount,1,count [count]bloop.returnsum.endproc The LASM code Example Dot Product From Chassaing
L. Boulianne.def_dotp4clasmfunc Define and ASM function called from C Start a section of Linear assembly _dotp4clasmfunc:.cproc ap, bp, count Name of the function Arguments of the function Set up your variables (similar to C).reg a, b, prod, sum Example Dot Product From Chassaing
L. Boulianne zero sum Initialize your sum to zero Load the value from memory pointed by ap, copy it to register a and increment the pointer by 1 ldh *ap++,a Do the same thing with b ldh*bp++,b ldh stands for load half word (a short in C) Example Dot Product From Chassaing
L. Boulianne Multiply a and b and write the result to prod mpya,b,prod Add sum and prod and write the result to sum addprod,sum,sum Decrement count by 1 subcount,1,count Example Dot Product From Chassaing
L. Boulianne If count is different than 0, branch to loop Return sum as the output of your function (exactly Like the return command in C) End linear assembly function.endproc [count]bloop.returnsum Example Dot Product From Chassaing
L. Boulianne Circular Addressing
L. Boulianne AMR Addressing mode register Read Chassaing at pages : 82-83
L. Boulianne AMR Addressing mode register
L. Boulianne AMR Addressing mode register How to modify the AMR ? MVKL.S20x0004,B2 MVKH.S20x0005,B2 MVC.S2B2,AMR MVC is the only function which can modify the content of a control register Be sure to reset the AMR at the end of your function Also, do the same inside your interrupt routine, check SPRU 187 to know how to modify the AMR from C There is a good example on how AMR works in SPRU189 at page 97-98
L. Boulianne For more Information Read Chaissaing at pages : and Read Kuo and Gan at pages : Read TMS320C6000 Optimizing Compiler User's Guide : Chapter 4 (SPRU187) It contains the description of the directives (.trip,.cprog,.reg, etc.) Read TMS320C6000 CPU and Instruction Set Reference Guide (SPRU189) It contains the description of the instruction set (add, mpy, sub, mv, etc.)
L. Boulianne Questions ?