Memory Models 

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.

 MODEL directive
.MODEL memory_model
Where memory_model can be:
  • TINY
  • LARGE or
  • HUGE.

TINY Model:

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.
On assembling and linking a source file, the tiny model automatically generates a com file, which is smaller in size than an exe file.

SMALL Model:

In the SMALL model all code is placed in one physical segment and all data in another physical segment.
In this model, all procedures and variables are addressed as NEAR by pointing to their offsets only.


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.
In this model, all code elements (procedures) are addressed as NEAR and data elements (variables) are addressed as FAR.


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.

LARGE Model:

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).

HUGE Model:

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.

Memory Model Size of Code Size of Data
TINY Code + Data < 64KB Code + data < 64KB
SMALL Less than 64KB Less than 64KB
MEDIUM Can be more than 64KBLess than 64 KB
COMPACT Less than 64KB Can be more than 64KB
LARGE* Can be more than 64KCan be more than 64KB
HUGE** Can be more than 64KCan be more than 64KB

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 addresses.
The only difference between these two models is that the TINY model generates a .COM module in which far references cannot be used, whereas the SMALL model generates a .exe module.

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.