
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide
[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
There are various ways to produce an executable program whose memory map
comprises separate code, data, and stack segments. The way a particular
program addresses the different areas of its memory map is determined by
the program's memory model.
A memory model specifically describes how executable code and data are
addressed within a program. For example, the 8086 imposes a limit of 64 KB
in any given segment, so a program with more than 64 KB of executable code
must be mapped into more than one executable code segment. Similarly, a
program with more than 64 KB of data must store that data in at least two
different data segments. Thus the simple memory model shown in Figure
19-1 can be elaborated upon--into four different memory models. (See
Figure 19-2.)
The memory model you use affects how your program uses segment registers.
In a small-model program, the CS and DS registers can be initialized at
the start of a program and left undisturbed for the duration. Contrast
this with a large-model program, where the CS register must be changed
whenever the program branches from one code segment to another, and the DS
or ES registers must often be updated whenever data from different
segments must be accessed.
Some high-level language compilers let you specify which memory model to
use. (See your compiler documentation for more information.) If you know
your program contains fewer than 64 KB of executable code and fewer than
64 KB of data, you can explicitly request such a compiler to generate a
small-model executable program. (This is the memory model we have used in
all the assembly-language examples in previous chapters.) Other compilers
can use a compact, medium, or large model, regardless of the program size.
Whatever the case, you should know what memory model your compiler uses if
you want to understand how the different parts of an executable program
fit together.
Model Number of Code Segments Number of Data Segments
--------------------------------------------------------------------------
Small 1 1
Compact 1 More than 1
Medium More than 1 1
Large More than 1 More than 1
--------------------------------------------------------------------------
Figure 19-2. Four common memory models.
Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson