11.14 Memory Models

The compiler supports several memory models. Command-line options are available for selecting the optimum memory model for your application, based on the specific device that you are using and the type of memory usage.

Table 11-1. Memory Model Command-Line Options
OptionMemory DefinitionDescription
-msmall-dataPlace all data in Near Data Space (Notes 1, 2).Permits the use of direct operations on memory, like PIC18 devices.
-msmall-scalarPlace scalar variables into Near Data Space. This is the default (Notes 1, 3).Scalar variables, single object entities such as int or float variables, are allocated into Near Data Space.
-msmall-codeUse short-calls and branches to transfer control. This is the default (Note 4).Function calls use the RCALL instruction.
-mlarge-codeUse long-calls and goto instructions, where possible.Function calls use the CALL instruction.
-mconst-in-dataconst qualified objects are allocated in data memory.Values copied from program memory by startup code.
-mconst-in-codeconst qualified objects located in program memory.Values accessed are directly from program Flash.
-mconst-in-auxflashconst qualified objects located in auxiliary Flash; this option is Device Dependent.Values are accessed directly from auxiliary program Flash.
Note:
  1. The extent of Near Data Space is Device Dependent; check the data sheet of the device you are using. If the memory space is fully consumed, the linker will issue an error message.
  2. The language tool will default to small data memory models when the selected device memory does not exceed the near data size.
  3. The small scalar memory model can be combined with the large data model to effectively place all scalars in the near Data Space and all aggregates (structures, unions, arrays) outside of the Near Data Space. The linker can place such objects in the Near Data Space if it is not fully consumed.
  4. Unlike the data memory models, the code size is not related to the total size of the program text but rather the distance between branches and calls. Note that a conditional branch instruction is always relative, so a single function may have a size limit.

The command-line options apply globally to the modules being compiled. Individual variables and functions can be declared as near, far or in eds to better control the code generation. For information on setting individual variable or function attributes, see Variable Attributes and Function Specifiers.