您的位置:首页 > 其它

The near and far keywords(DSP & CCS)

2012-10-29 17:28 337 查看
// 摘自: TMS320C6000 Optimizing Compiler v7.4 User`s Guide.pdf

====================================================================================================

The C6000 C/C++ compiler extends the C/C++ language with the near and far keywords to specify how global and static variables are accessed and how functions
are called.

Syntactically, the near and far keywords are treated as storage class modifiers. They can appear before, after, or in between the storage class specifiers
and types. With the exception of near and far, two storageclass modifiers cannot be used together in a single declaration.
The following examples are legal combinations of near and far with other storage class modifiers:

far static int x;
static near int x;
static int far x;
far int foo();
static far int foo();

near and far Data Objects

Global and static data objects can be accessed in the following two ways:

near keywordThe compiler assumes that the data item can be accessed relative to the data page pointer.
For example:

LDW *+dp(_address), a0

far keywordThe compiler cannot access the data item via the DP. This can be required if the total amount
of program data is larger than the offset allowed (32K) from the DP. For example:

MVKL _address, a1

MVKH _address, a1

LDW *a1, a0

Once a variable has been defined to be far, all external references to this variable in other C files or headers must also contain the far keyword. This is also true of the near keyword. However, you
will get compiler or linker errors when the far keyword is not used everywhere. Not using the near keyword everywhere only leads to slower data access times.

If you use the DATA_SECTION pragma, the object is indicated as a far variable, and this cannot be overridden. If you reference this object in another file, then you need to use extern far
when declaring this object in the other source file. This ensures access to the variable, since the variable might not be in the .bss section. For details, seeSection 6.9.6.

NOTE: Defining Global Variables in Assembly Code


If you also define a global variable in assembly code with the .usect directive (where the variable is not assigned in the .bss section) or you allocate a variable into separate section using a #pragma DATA_SECTION directive; and you want to reference that
variable in C code, you must declare the variable as extern far. This ensures the compiler does not try to generate an illegal access of the variable by way of the data page pointer.


When data objects do not have the near or far keyword specified, the compiler will use far accesses to aggregate data and near accesses to non-aggregate data. For more information on the
data memory model and ways to control accesses to data, see Section 7.1.5.1.

Near and far Function Calls

Function calls can be invoked in one of two ways:

near keyword The compiler assumes that destination of the call is within
± 1 M word of the caller. Here the compiler uses the PC-relative branch instruction.

B _func

far keyword The compiler is told by you that the call is not within
± 1 M word.

MVKL _func, al

MVKH _func, al

B _func

By default, the compiler generates small-memory model code, which means that every function call is

handled as if it were declared near, unless it is actually declared far.

For more information on function calls, see Section 7.1.6.

-------------------------------------------------------------------------------------------------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐