Memory models, Mory model (see the, E the – Zilog Z8F0130 User Manual

Page 223: Section

Advertising
background image

UM013037-1212

Memory Models

Zilog Developer Studio II – Z8 Encore!

User Manual

199

struct{

near char num;

/* Warning: near space specifier is ignored. */

near char * ptr;

/* Correct: ptr points to a char in near memory.

ptr itself is stored in the memory space of structure (far). */

} far mystruct;

/* All of mystruct is allocated in far memory.*/

Memory Models

The Z8 Encore! C-Compiler provides two memory models:

Small Memory Model

– see page 199

Large Memory Model

– see page 200

Each of these models directs the compiler to where to place data in memory by default, to
maximize the efficiency of an application. This feature allows you to control where global
and static data are allocated, as well as where frames containing local and parameter data
are stored.

Small Memory Model

In the small memory model, global variables are allocated in the RData address space. The
address of these variables is 8 bits. The locals and parameters are allocated on the stack,
which is also located in the RData address space. The address of a local or parameter is an
8-bit address. Global variables can be manually placed into the EData or ROM address
space by using the address specifiers

far

and

rom

, respectively. Local (nonstatic) vari-

ables and parameters are always allocated in the RData address space, and any address
specifiers used in their declarations are ignored. Use of the small memory model does not
impose any restriction on your code size; only data memory is affected by the choice of
model.

The small memory model always produces more efficient code than the large model if
your application can use it. The use of the small model places stringent limits on the data
space available for the stack and data. It does help to produce smaller code, by enabling
the compiler to use shorter instructions with more compact addressing modes. If you are
near but slightly over the data-space limits of the small model, you might still be able to
use the small model by declaring enough selected global or static variables as

far

to get

your use of RData down to the available space.

The code used to access those

far

variables is less efficient than code to access

near

(i.e.,

RData) variables. Therefore, if you follow this plan, you must identify variables that are
seldom accessed in your program and designate them as

far

.

Advertising