DSP

DSP++ .global,.section,.var

2019-07-13 12:47发布

.GLOBAL, Make a Symbol Available Globally

Syntax:

.GLOBAL symbolName1[, symbolName2,…];
where:
symbolName – the name of a global symbol. A single .GLOBAL directive may define the global scope of any number of symbols on one line, separated by commas.

Example (SHARC and TigerSHARC code):

.VAR coeffs[10]; // declares a buffer
.VAR taps=100; // declares a variable
.GLOBAL coeffs, taps; // makes the buffer and the variable
// visible to other files

Example (Blackfin code):

.BYTE coeffs[10]; // declares a buffer
.BYTE4 taps=100; // declares a variable
.GLOBAL coeffs, taps; // makes the buffer and the variable
// visible to other files

.SECTION, Declare a Memory Section

The .SECTION directive marks the beginning of a logical section mirroring an array of contiguous locations in your processor memory. Statements between one .SECTION directive and the following .SECTION directive (or the end-of-file instruction), comprise the content of the section.

TigerSHARC and Blackfin Syntax:

.SECTION/qualifier [/qualifier] sectionName [sectionType];
SHARC Syntax:
.SECTION[/TYPE/qualifier sectionName [sectionType];

.VAR, Declare a Data Variable or Buffer

The .VAR directive declares and optionally initializes variables and data buffers. A variable uses a single memory location, and a data buffer uses an array of memory locations.
When declaring or initializing variables:
• A .VAR directive may appear only within a section. The assembler associates the variable with the memory type of the section in which the .VAR appears. • A single .VAR directive can declare any number of variables or b­uffers, separated by commas, on one line. Unless the absolute placement for a variable is specified with a RESOLVE() command (from an .ldf file), the linker places variables in consecutive memory locations. For example, .VAR d,f,k[50]; sequentially places symbols x, y, and 50 elements of the buffer z in the processor memory. Therefore, code example may look like:
.VAR d;
.VAR f;
.VAR k[50]; • The number of initializer values may not exceed the number of variables or buffer locations that you declare. • The .VAR directive may declare an implicit-size buffer by using empty brackets [ ]. The number of initialization elements defines the length of the implicit-size buffer. At runtime, the length operator can be used to determine the buffer size. For example,
.SECTION data1;
.VAR buffer [] = 1,2,3,4;
.SECTION program;
LO = LENGTH( buffer ); // Returns 4