Tutorial 3 Slides on Asembly Language

advertisement
ECSE436 Tutorial
Assembly and Linear Assembly
Evgeny Kirshin,
05/10/2011
Outline
•
•
•
•
•
Introduction to Assembly
Linear Assembly
AMR
Reading
Demo: simple sine-wave generator
E. Kirshin
TMS320 Assemby Language
E. Kirshin
C6000 ISA
E. Kirshin
Instruction Packing
E. Kirshin
Sample Instructions
E. Kirshin
Sample Instruction
E. Kirshin
Instruction List
E. Kirshin
Instruction List
E. Kirshin
C program calling and ASM
function
E. Kirshin
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
E. Kirshin
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…
E. Kirshin
What is Linear Assembly ?
TI Linear Assembly
Efficiency
Ease of use
C code
Assembly
E. Kirshin
What is Linear Assembly ?
It is a cross between C and Assembly
Enables you to write assembly-like programs
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 (e.g.,
hardware circular buffers)
E. Kirshin
File extensions
File extension for c is .c
File extension for linear assembly is .sa
File extension for low-level assembly is .asm
E. Kirshin
Example Dot Product
From Chassaing
//DOTPclasm.c
short dotp4clasmfunc(short *a, short *b, short ncount);
#include <stdio.h>
#define count 4
short x[count] = {0,1,2,3};
short y[count] = {100, -20, 30, -20};
volatile int result = 0;
main()
{
}
Function written in LASM
result = dotp4clasmfunc(x,y,count);
printf("result = %d decimal \n", result);
E. Kirshin
Example Dot Product
From Chassaing
The LASM code
_dotp4clasmfunc:
loop:
[count]
.def
.cproc
.reg
zero
ldh
ldh
mpy
add
sub
b
.return
.endproc
_dotp4clasmfunc
ap, bp, count
a, b, prod, sum
sum
*ap++,a
*bp++,b
a,b,prod
prod,sum,sum
count,1,count
loop
sum
E. Kirshin
Example Dot Product
From Chassaing
Define and ASM function called from C
.def
_dotp4clasmfunc
Name of the function
Start a section of Linear assembly
_dotp4clasmfunc:
.cproc
ap, bp, count
Arguments of the function
Set up your variables (similar to C)
.reg
a, b, prod, sum
E. Kirshin
Example Dot Product
From Chassaing
Initialize your sum to zero
zero
sum
Load the value from memory pointed by ap,
copy it to register a and increment the pointer by 1
ldh
*ap++,a
ldh stands for load half word (a short in C)
Do the same thing with b
ldh
*bp++,b
E. Kirshin
Example Dot Product
From Chassaing
Multiply a and b and write the result to prod
mpy
a,b,prod
Add sum and prod and write the result to sum
add
prod,sum,sum
Decrement count by 1
sub
count,1,count
E. Kirshin
Example Dot Product
From Chassaing
If count is different than 0, branch to loop
[count]
b
loop
Return sum as the output of your function (exactly
Like the return command in C)
.return
sum
End linear assembly function
.endproc
E. Kirshin
Circular Addressing
E. Kirshin
AMR
Addressing mode register
Read Chassaing at pages : 82-83
E. Kirshin
AMR
Addressing mode register
E. Kirshin
AMR
Addressing mode register
How to modify the AMR ?
MVKL
MVKH
MVC
.S2
.S2
.S2
0x0004,B2
0x0005,B2
B2,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 the book
by Chassaing to know how to modify the AMR from C
There is a good description on how AMR works in SPRA645, see further
E. Kirshin
References: TI documents
• TMS320C6000 Optimizing Compiler User's Guide
(SPRU187).
Chapter 4 contains the description of the directives
(.trip, .cprog, .reg, etc.)
• TMS320C67x/C67x+ DSP CPU and Instruction Set
Reference Guide (SPRU733).
Contains the description of the instruction set (add, mpy,
sub, mv, etc.)
• TMS320C6000 Assembly Language Tools
(SPRU186V).
• Circular Buffering on TMS320C6000 (SPRA645).
Nice description of hardware circular buffering and the
AMR register
E. Kirshin
References: books
• Chaissaing, pages : 87-88 and 112-115
• Kuo and Gan, pages : 243-245
Additional book:
S.A.Tretter. Communication System Design
Using DSP Algorithms. SpringerLink, 2008
Contains good description of the AIC, McBSP,
interrupts and sine-wave generation examples.
Available online in PDF (from McGill).
E. Kirshin
Questions ?
E. Kirshin
Download