The Freescale 56800E C Compiler supports large and small program and data memory models as shown in the following table. The small data model is more code efficient. However, sometimes the application requires a larger data address space.
| Section | Small Data Model | Large Data Model | ||
|---|---|---|---|---|
| Size (KB) | Range (Word Address) | Size (MB) | Range (Word Address) | |
| CODE (P:memory) | 128 | 0 - 0xFFFF | 1 | 0 - 0x7FFFF |
| DATA (X:memory) | 128 | 0 - 0xFFFF | 32 | 0 - 0x7FFFF |
| DATA (X:memory) character data | 64 | 0 - 0xFFFF | 16 | 0 - 0x7FFFF |
The large data memory model allows data to be placed in memory at addresses greater than the 16-bit address limitation of the small data model. The large data memory model can be selected at DSC Compiler > Processor Options in the Tool Settings panel. This selection informs the compiler that global and static data should be addressed with the 24-bit variants of the absolute addressing modes of the device. Also in the large memory model, pointers are treated as 24-bit quantities when moved from register to register, memory to register, or register to memory. For information on how the large memory model is selected, see the Freescale 56800/E Hybrid Controllers: MC56F83xx/DSP5685x Family Targeting Manual.
One likely scenario in an embedded programming environment is that the total static and global data size, that is, the total size of data objects that the compiler accesses with absolute addressing modes (X:xxxx or X:xxxxxx addressing modes) will comfortably reside within the 16-bit data addressing range. However, the heap (dynamically allocated data memory) or the stack (local, automatic data memory) may require extended addressing as this data may extend beyond the 16-bit address range.
To optimize the program size, use the CodeWarrior IDE targets settings panel M56800E Processor: Large Data Model: Globals live in lower memory panel option in conjunction with the large data memory model. The Globals live in lower memory panel option reverts the absolute addressing modes to the small data model for static and global variables, while using the large memory model for any address pointers or local variables. Thus, for static and global variables, the efficiency of the small data model is retained even for programs where the total data size may exceed the 16-bit addressing range.
The following listing shows the code generation differences between the large and small data model. In this example, the code performs a bubble sort on an array of integers. At maximum optimization, the code runs in 579 cycles in the small data memory model. The code takes 760 cycles using the large data memory model. When the large data memory model and Globals live in lower memory option is selected, the code runs in 729 cycles. The difference in the cycle count of the two large data model runs is due to the way global variables are addressed. The Globals live in lower memory option forces the access of the global variable "next" to be there as it would be for the small data model.
int vector[] = { 3,7,6,1,2,5 }; int next; int main() { int i=0, j=0; int sz = sizeof(vector)/sizeof(int); for (i=0; i<sz; i++){ for(j=0; j<sz-i; j++){ if (vector[j]>vector[j+1]) { next=vector[j]; vector[j]=vector[j+1]; vector[j+1]=next; } } } } }
| Small Data Model | Large Data Model | Large Data Model and Global Live in Lower Memory |
|---|---|---|
| 579 cycles | 760 cycles | 729 cycles |
If the Globals live in lower memory option is selected, be sure to locate the .data and .bss sections in lower memory. Dynamically allocated memory and the stack may be located in either lower or upper memory for the large data model.