UMBC CMSC 211

UMBC | CSEE


Memory Models

Using what you learned in this chapter, we can talk about memory models now. We have always used SMALL memory model because we needed to force all memory references to near pointers and near calls/jumps. There are actually six models, TINY, SMALL, COMPACT, MEDIUM, LARGE, and HUGE. This directive simply sets the assembler to use the proper sized addresses. It useful to be able to separately specify the data and code address as near or far. The TINY model puts everything into one segment, the PSP, the code, the data, and the stack. The HUGE uses multiply code segments (FAR calls) and multiple data s (FAR calls) and multiple data segments (FAR pointers), including segments that are larger than 64K, which requires special treatment. That leaves:

size Code Segments Data Segments
SMALL one (near calls) one (near pointers)
COMPACT one (near calls) multiple (far pointers)
MEDIUM multiple (far calls) one (near pointers)
LARGE multiple (far calls) multiple (far pointers)

 

When there are multiple code segments, the PROCs are to return with ar far ret instruction, and should be referenced in other files as EXTRN Label : FAR.

As a general rule, if you are combining assembly programs with high-level languages, you should use the saem model in assembly as the high-level language, where the model is much more important!

In order to allow a true small mode program, the assemblers automatically group .DATA and .STACK segments into a single segment. Since the stack data must come as the end of the program, the segments always occur in the order PSP, .CODE, .DATA and stack.


UMBC | CSEE