The memory model specifies the memory size assigned to each of the different parts or segments of a program. There exist different memory models for the 8086 proceessor
The .MODEL Directive
The memory model directive specifies the size of the memory the program needs. Based on this directive, the assembler assigns the required amount of memory to data and code.
Each one of the segments (stack, data and code), in a program, is called a logical segment . Depending on the model used, segments may be in one or in different physical segments.
In MASM 6.X, segments are declared using the .MODEL directive. This directive is placed at the very beginning of the program, or after the optional title directive.
In the TINY model both code and data occupy one physical segment.
Therefore, all procedures and variables are by default addressed
as NEAR, by pointing at their offsets in the segment.
In the SMALL model all code is placed in one physical segment and all data
in another physical segment.
In the COMPACT model, all elements of code (e.g. procedures) are placed
into one physical segment. However, each element of data can be placed
by default into its own physical segment. Consequently, data elements
are addressed by pointing both at the segment and offset addresses.
The MEDIUM model is the opposite of the compact model. In this model data elements are treated as NEAR and code elements are addressed as FAR.
In the LARGE model both code elements (procedures) and data elements (variables) are put in different physical segments. Procedures and variables are addressed as FAR by pointing at both the segment and offset addresses that contain those elements. However, no data array can have a size that exceeds one physical segment (i.e. 64 KB).
The HUGE memory is similar to the LARGE model with the exception that a data array may have a size that exceeds one physical segment (i.e. 64 KB).
The following table summarizes the use of models and the number and sizes of physical segments that are used with each of the models.
Table 1: Memory Models
(*) For the LARGE model, the largest arrays size can not exceed 64 KB.(br) (**)For the HUGE model, an array may have a size greater than 64 KB and hence can span more than one physical segment.
Use of memory models:
The amount of data that has to be manipulated and code that needs to be written are the mojor factors in determining the choice of an appropriate model. The following are guidelines to help chose the right model for a program.
For a small fast program that operates on small quantities of data, the
SMALL or TINY models are the most suitable ones. These models allow up
to 64K of memory (i.e. one single physical segment), but the executable
code is fast since only near references are used in the calculation of
For very long programs that require more than one code segment and operate on large amounts of data which would require more than one data segment, the LARGE and HUGE models are most appropriate.