Chapter2 ASM
Chapter2 ASM
Assembly Language
Learning Objectives
The TMS320C6000 is supported by a set of software
development tools, which includes an optimizing
C/C++ compiler, an assembly optimizer, an assembler,
a linker, and assorted utilities.
.bbs RAM
.data EEPROM
.text
ROM
Memory allocation
Chapter 2, Slide 6 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
COFF: Sections assembler directives
You can create subsections of any section to give
you tighter control of the memory map. Subsections
are created using the .sect and .usect directives.
Initialized sections contain data or code. The .text
and .data sections are initialized; named sections
created with the .sect assembler directive are also
initialized.
Uninitialized sections sections reserve space in the
memory map for uninitialized data. The .bss section
is uninitialized; named sections created with the
.usect assembler directive are also uninitialized.
Because most systems contain several types of
memory, using sections can help you use target
memory more efficiently.
Initialized sections
.text
.data
.sect “ section name”
Uninitialized sections
.bss symbol, size in bytes [, alignment[, bank offset] ]
symbol .usect “section name”, size in bytes [, alignment[, bank offset] ]
***************************************************
51 ** Define a named section for interrupt vectors **
52 ****************************************************
53 00000000 .sect ”vectors”
54 00000000 00000012’ B sum
55 00000004 00008000 NOP 5
Chapter 2, Slide 9 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
COFF: Sections linking process
The linker produces executable COFF object
modules. An executable object file has the same
COFF format as object files that are used as linker
input; the sections in an executable object file,
however, are combined and relocated into target
memory.
To run a program, the data in the executable object
module must be transferred, or loaded, into target
system memory
Loading a Program
COFF COFF
object file Linker executable file TARGET
Memory
Realocation
Chapter 2, Slide 10 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
COFF: Sections linking process
Label Identify a line of code or a variable and represent a memory address that
contains either an instruction or data. if used, they must begin in column 1.
|| An instruction that executes in parallel with the previous instruction
signifies this with parallel bars (||).
Condition There are five registers available for conditions: A1, A2, B0, B1, and
B2. If blank, the instruction always executes.
Instruction (See next slide)
Unit .D1 and .D2 Data/addition/subtraction.
.L1 and .L2 ALU/compares/long data arithmetic.
.M1 and .M2 Multiply. S1 and .S2
.S1 and .S2 Shift/ALU/branch/bit field
Operands Symbols, Cte or Expressions
. .L1 .L2 .
. .L1 .L2 .
. .
.D1
.D1 .D2
.D2
A15 B15
32-bits 32-bits
Memory
Chapter 2, Slide 17 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
Assembly Instructions: set by functional units
.S Unit .L Unit .M Unit .D Unit
ADD ABS MPY ADD
ADDK ADD MPYH ADDAB
ADD2 AND MPYLH (B/H/W)
AND CMPEQ MPYHL LDB
B CMPGT SMPY (B/H/W)
CLR CMPLT SMPYH MV
EXT LMBD NEG
MV MV STB
MVC NEG (B/H/W)
MVK NORM SUB
MVKL, MVKH NOT SUBAB
NEG OR (B/H/W)
NOT SADD ZERO
OR SAT
SET SSUB
SHL, SHR SUB
SSHL SUBC
SUB, SUB2 XOR
XOR ZERO
ZERO
macname names the macro. You must place the name in the source
statement’s label field. The assembler places the macro name in the
internal opcode table, replacing any instruction or previous macro
definition with the same name.
.macro is the directive that identifies the source statement as the first line
of a macro definition.
.mexit is an assembly directive that functions as a goto.
.endm is the directive that terminates the macro definition.
Macro call: The following code calls the sadd4 macro with four arguments:
10
11 0000000 sadd4 A0,A1,A2,A3
Macro expansion: The following code shows the substitution of the macro definition for the macro
call. The assembler substitutes A0, A1, A2, and A3 for the r1, r2, r3, and r4 parameters of sadd4.
.mlib filename
.mlib When the assembler encounters the .mlib directive, it opens the
library named by filename and creates a table of the library’s
contents. If one of these macros is called, the assembler
extracts the entry from the library and loads it into the macro table.
filename the library name.
You can use the Archiver to create a macro library by including the desired files in
an archive. A macro library is no different from any other archive, except that the
assembler expects the macro library to contain macro definitions.
ar6x –t function
.M
.M
The . M unit performs multiplications in
hardware
.M
.M
.?
.? MPY .M a1, x1, prod
ADD .? Y, prod, Y
.M
.M
.L
.L MPY .M a1, x1, prod
ADD .L Y, prod, Y
. .L
.
.
.L MPY .M a1, x1, prod
ADD .L Y, prod, Y
A15
32-bits
. .L
.
.
.L MPY .M A0, A1, A3
ADD .L A4, A3, A4
A15
32-bits
. .L
.
.
.L MPY .M A0, A1, A3
ADD .L A4, A3, A4
A15
32-bits
. .L
.
.
.L
A15
32-bits
A15
.D
.D
32-bits
Data Memory
Chapter 2, Slide 62 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
Load Unit “.D”
Register File A
It is worth noting at this
A0 a1 stage that the only way to
A1 x1 access memory is through the
A2 .D unit.
A3 prod .M
.M
Y
. .L
.
.
.L
A15
.D
.D
32-bits
Data Memory
Chapter 2, Slide 63 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
Load Instruction
. .L
.
.
.L
A15
.D
.D
32-bits
Data Memory
Chapter 2, Slide 64 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
Load Instructions (LDB, LDH,LDW,LDDW)
A15
.D
.D
32-bits
Data Memory
Chapter 2, Slide 65 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
Using the Load Instructions
FFFFFFFF
16-bits
16-bits
FFFFFFFF
16-bits
FFFFFFFF
16-bits
MVKL a, A5
MVKH a, A5
Example 2
Register File A
A0 a MVKL pt1, A5
A1 x MVKH pt1, A5
A2 MVKL pt2, A6
A3 prod .M
.M MVKH pt2, A6
Y
LDH .D *A5, A0
. .L LDH .D *A6, A1
.
.
.L
MPY .M A0, A1, A3
ADD .L A4, A3, A4
A15
.D
.D
32-bits
Data Memory
Chapter 2, Slide 75 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
Creating a loop
Data Memory
Chapter 2, Slide 81 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
Which unit is used by the B instruction?
MVKL .S pt1, A5
Register File A
MVKH .S pt1, A5
A0 a .S
.S MVKL .S pt2, A6
A1 x MVKH .S pt2, A6
A2
prod .M
.M
A3 .M
.M
Y loop LDH .D *A5, A0
. LDH .D *A6, A1
. .L
.L
. .L
.L MPY .M A0, A1, A3
ADD .L A4, A3, A4
.D
.D B .S loop
A15 .D
.D
32-bits
Data Memory
Chapter 2, Slide 82 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
3. Create a loop counter.
MVKL .S pt1, A5
Register File A
MVKH .S pt1, A5
A0 a .S
.S MVKL .S pt2, A6
A1 x MVKH .S pt2, A6
A2 MVKL .S count, B0
prod .M
.M
A3 .M
.M
Y loop LDH .D *A5, A0
. LDH .D *A6, A1
. .L
.L
. .L
.L MPY .M A0, A1, A3
ADD .L A4, A3, A4
.D
.D B .S loop
A15 .D
.D
32-bits
B registers will be introduced later
Data Memory
Chapter 2, Slide 83 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
4. Decrement the loop counter
MVKL .S pt1, A5
Register File A
MVKH .S pt1, A5
A0 a .S
.S MVKL .S pt2, A6
A1 x MVKH .S pt2, A6
A2 MVKL .S count, B0
prod .M
.M
A3 .M
.M
Y loop LDH .D *A5, A0
. LDH .D *A6, A1
. .L
.L
. .L
.L MPY .M A0, A1, A3
ADD .L A4, A3, A4
.D
.D SUB .S B0, 1, B0
A15 .D
.D
B .S loop
32-bits
Data Memory
Chapter 2, Slide 84 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
5. Make the branch conditional based on the
value in the loop counter
What is the syntax for making instruction
conditional?
[condition] Instruction Label
e.g.
[B1] B loop
Data Memory
Chapter 2, Slide 87 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
More on the Branch Instruction (1)
32-bit
5-bit register
B code
Data Memory
Chapter 2, Slide 102 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
Chapter 1
- End -