A Courseware for DSP linear assembly

Source: Internet
Author: User

Reprinted, do not know the source

DSP Technology and Application --

Introduction to linear assembly language


Introduction to linear assembly language
• Assemble the code structure
• Linear assembly language Introduction


Assembly code structure
Label: parallel bars [condition] Instruction Unit
Operands; Comments
(1) Label
A label is used to define a line of code or a variable. It represents
Or data storage address. The colon following the label is optional.
The 1st characters in a must be letters or underscores (_) followed by one word.
Mother;
The 1st characters of B must be in the 1st column of the file;
C can contain a maximum of 32 characters;
D parallel commands cannot use labels.
(2) parallel bars parallel symbols |

Assembly code structure
Label: parallel bars [condition] Instruction
Unit operands; Comments
(3) [condition] conditions
A If the command does not specify the conditions, the command is always executed;
B. If a condition is specified and the condition is true, the command is executed;
C If a condition is specified and the condition is false, the command is not executed.
For example, [a1] A1! = 0 A1 = 0
[! A1] a1 = 0 A1! = 0


Assembly code structure
Label: parallel bars [condition] Instruction Unit
Operands; Comments
4 instruction command
Assembly Code Commands include pseudocommands and command mnemonic
A pseudo-directive is used to control the assembly process or define the data structure in the assembly language.
All pseudocommands start with dots.
For example:
. Sect "name"
. Double Value
. Float Value
. Byte value
Command B indicates a valid microprocessor command, which executes program operations.


Assembly code structure
Label: parallel bars [condition] Instruction
Unit operands; Comments
5 uint function unit
C6000 has eight functional units, each of which has
Two types. The function unit starts with ".", followed
Feature units.
. S1. S2. L1. l2. M1. m2. D1. D2
Another cross-channel such as. l1x


Assembly code structure
Label: parallel bars [condition] Instruction
Unit operands; Comments
6 operands operations
The operands are composed of constants, symbols, constants, and symbols.
.
The operands must be separated by commas.
7 Comments
; Annotation can start with any column
* The comment must start in the first column.


Introduction to linear assembly language
Basic Structure of linear Assembly Statements
Pseudocommands in linear assembly
Linear Assembly Resource arrangement
C code conversion to linear assembly


Basic Structure of linear Assembly Statements
• The basic format is the same as that of the Assembly Language and must be an ascii code
File, the extension must be ". Sa", used for assembly Optimization
Input File
• Label [[[:] [|] [[register] mnemonic [Unit
Specifier] [operand list] [; commend]


Pseudocommands in linear assembly
1. Call a function
. Call [ret_reg =] func_name (arg1, arg2) (Procedure only in the process)
Valid
2. Define an optimizer that can be optimized by the Assembly optimizer and can be called as a function by C/C ++.
Uses the pseudo commands of linear assembly code segments.
Label. cproc [vari1 [, vari2,…] Start
. Endproc ended
3. Define a pseudo command for a linear assembly code segment that can be optimized by the Assembly optimizer.
Label. Proc [vari1 [, vari2,…] Start
. Endproc ended


Pseudocommands in linear assembly
4. Indicates irrelevant pseudocommands related to memory addresses
. Mdep [symbol1], [symbol2] 1, 2
. No_mdep the memory in the function segment defined later
Address unrelated
5. Define variables, or describe the pseudo commands of the numeric variables stored in the register:
. Reg variable1 [, variable2,…]
6. return values of the process
. Return [argument]
7. pseudoinstructions indicating the number of iterations
Label. Trip minimum value


Linear Assembly Resource arrangement
The read instruction (LDH) must use the. d unit.
The multiplication command (mpy) must use. m units.
Addition command (ADD) must use. l Unit
The subtraction command (sub) must use the. s unit.
Jump command (B) Must use. s Unit


C code conversion to linear assembly
• Short dp (short * m, short * n, short count)
•{
• Short I;
• Short product;
• Short sum = 0;
• For (I = 0; I <count; I ++)
•{
• Product = m [I] * n [I];
• Sum + = product;
•}
• Return (SUM );
•}


C code conversion to linear assembly
• Step 1: Define the function name and implement parameter transfer
Short dp (short * m, short * n, short count)
. Def _ DP
_ DP. cproc cptr0, cptr1, vptr
1). Def is short for definition.
2). cproc indicates that the function is a C-callable function, and the value is
Parameters passed


C code conversion to linear assembly
• Step 2: Set the register for temporarily storing temporary data
Name, completed by. Reg (Register)
. Reg addr_a, addr_x
. Reg m, n
. Reg product, Sum

C code conversion to linear assembly
• Step 3: Initialize data
MV cptr0, addr_a
MV cptr1, addr_x
Zero sum
In the first two sentences, store the first addresses of arrays A [] and X [] into the names addr_a.
And addr_x register variables, so that the subsequent implementation of the array
The last sentence is to clear the accumulate register.


C code conversion to linear assembly
• Step 4 process the loop body of the program
Define a label loop: as a flag returned by the loop; then
Rewrite the statement to an assembly statement in the order of the original C Program Statement (not required
Set the functional unit for executing the command ):
Product = m [I] * n [I];
Rewrite
LDH * addr_a ++, m
LDH * addr_x ++, n
Mpy m, n, product
Sum + = product;
Rewrite
Add sum, product, Sum


C code conversion to linear assembly
• Reduce the cyclic variable vptr (count) by one; Use c6x
Determine whether the vptr is zero
Execute the redirection command under the condition of disconnection:
If (vptr! = 0) then B Loop
• Finally,. Return implements data return.
• After all the work is done, use. endproc as the function knot
Bundle flag.


C code conversion to linear assembly
•. Def _ DP
• _ DP. cproc cptr0, cptr1, vptr
•. Reg addr_a, addr_x
•. Reg m, n
•. Reg product, Sum
• MV cptr0, addr_a
• MV cptr1, addr_x
• Zero sum
• Loop:
• LDH * addr_a ++, m
• LDH * addr_x ++, n
• Mpy m, n, product
• Add sum, product, Sum
• Sub vptr, 1, vptr
• [Vptr] B Loop
•. Return sum
•. Endproc


C code conversion to linear assembly
• Short dp (short * m, short * n, short count)
•{
• Short I;
• Int pro_h, pro_l;
• Int sum_h = 0;
• Int sum_l = 0;
• Int sum = 0;
• Int * data_a = (int *) m;
• Int * data_x = (int *) N;
• COUNT = count> 1;
• For (I = 0; I <count; I ++)
•{
• Pro_l = _ mpy (data_a [I], data_x [I]);
• Pro_h = _ mpyh (data_a [I], data_x [I]);
• Sum_l + = pro_l;
• Sum_h + = pro_h;
•}
• Sum = sum_l + sum_h;
• Return (SUM );
•}



•. Def _ DP
• _ DP. cproc cptr0, cptr1, vptr
•. Reg addr_a, addr_x
•. Reg product0, product1, sum0, sum1
•. Reg m, n
• MV cptr0, addr_a
• MV cptr1, addr_x
• Zero sum0
• Zero sum1
• SHR vptr, 1, vptr
• Loop:
• LDW * addr_a ++, m
• LDW * addr_x ++, n
• Mpy m, n, product0
• Mpyh m, n, product1
• Add sum0, product0, and sum0
• Add sum1, product1, sum1
• Sub vptr, 1, vptr
• [Vptr] B Loop
• Add sum0, sum1, sum0
•. Return sum0
•. Endproc


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.