
Memory Models
SC100 C Compiler
6-5
6.2 Memory Models
The compiler architecture supports both 16-bit and 32-bit addresses. If the application is small enough to
allow all static data to fit into the lower 64K of the address space, then more efficient code can be
generated. This mode, the small memory model, is the default, and assumes that all addresses are 16-bit.
The big memory model does not restrict the amount of space allocated to addresses. This model is selected
with the option
-mb
when the shell is invoked.
When the compiler uses the big memory model to access a data object, whether static or global, it must use
a longer instruction that includes a 32-bit address. This operation requires an additional word, and as a
result it produces code that is larger, and in some cases, slower, than a similar operation using the small
memory model.
Example 6-4 illustrates the use of the
move.l
instruction in the big and small memory models. In this
example, the assembler interprets the address in the first instruction as a 32-bit address, and allocates the
maximum space for it
.
In the second instruction, the
<
symbol indicates to the assembler that this address
fits into a 16-bit space, thus preventing the allocation of unnecessary program memory.
Example 6-4. Big and small memory models
Big memory model (3 16-bit words):
move.l
address,d0
Small memory model (2 16-bit words):
move.l
<address,d0
Certain instructions can be used only in small memory mode. If
<
is omitted in conjunction with these
instructions, an error results. Example 6-5 shows the instruction
bmset.w
, which sets bit #zero in the
specified address, and is valid only in small memory mode.
Example 6-5. Small memory mode instruction
bmset.w #0001,<address
For maximum efficiency, it is recommended that you place data in the lower 64K of the memory map, in
order to enable the compiler to use small memory mode.
6.2.1 Linker Command Files
The SC100 linker refers to a linker command file at link time, for various runtime values, addresses and
labels. Two linker command files are provided, one for each memory mode. These files are
crtscsmm.cmd
, used in small memory mode, and
crtscbmm.cmd
, used when big memory mode is
selected. Both files are located in the
install-dir
/etc
directory.