The DATA_MEM_BANK Pragma

The DATA_MEM_BANK pragma aligns a symbol or variable to a specified internal data memory bank boundary. The constant specifies a specific memory bank to start your variables on. (See Figure 5-1 for a graphic representation of memory banks.) C6400+, C6740, and C6600 devices contain 8 memory banks. The value of constant can be 0, 2, 4, or 6.

The syntax of the pragma in C is:

#pragma DATA_MEM_BANK (symbol, constant)

The syntax of the pragma in C++ is:

#pragma DATA_MEM_BANK (constant)

Both global and local variables can be aligned with the DATA_MEM_BANK pragma. The DATA_MEM_BANK pragma must reside inside the function that contains the local variable being aligned. The symbol can also be used as a parameter in the DATA_SECTION pragma.

When optimization is enabled, the tools may or may not use the stack to store the values of local variables.

The DATA_MEM_BANK pragma allows you to align data on any data memory bank that can hold data of the type size of the symbol. This is useful if you need to align data in a particular way to avoid memory bank conflicts in your hand-coded assembly code versus padding with zeros and having to account for the padding in your code.

This pragma increases the amount of space used in data memory by a small amount as padding is used to align data onto the correct bank.

A value of 0 for the constant argument to DATA_MEM_BANK pragma causes the last five bits of the starting address to be 0x00. For a value of 2, the last five bits of the starting address will be 0x08 (0b01000). For a value of 4, the last five bits of the starting address will be 0x10 (0b10000). For a value of 6, the last five bits of the starting address will be 0x18 (0b11000).

The code in Example 7 uses the DATA_MEM_BANK pragma to specify the alignment of the x, y, z, w, and zz arrays. It then assigns values to all the array elements and prints the starting address of each array.