Structuring a MASM program using simplified segments requires use of several directives to assign standard names, alignment, and attributes to the segments in your program. These directives define the segments in such a way that linking with Microsoft high-level languages is easy.
The simplified segment directives are .MODEL, .CODE, .CONST, .DATA, .DATA?, .FARDATA, .FARDATA?, .STACK, .STARTUP, and .EXIT. These directives and the arguments they take are discussed in the following sections.
Summary: The main module is where execution begins.
MASM programs consist of modules made up of segments. Every program written only in MASM has one main module, where program execution begins. This main module can contain code, data, or stack segments defined with all of the simplified segment directives. Any additional modules should contain only code and data segments. Every module that uses simplified segments must, however, begin with the .MODEL directive.
The following example shows the structure of a main module using simplified segment directives. It uses the default processor (8086), the default operating system (OS_DOS), and the default stack distance (NEARSTACK). Additional modules linked to this main program would use only the .MODEL, .CODE, and .DATA directives and the END statement.
; This is the structure of a main module
; using simplified segment directives
.MODEL small, c ; This statement is required before you
; can use other simplified segment
; directives
.STACK ; Use default 1-kilobyte stack
.DATA ; Begin data segment
; Place data declarations here
.CODE ; Begin code segment
.STARTUP ; Generate start-up code
; Place instructions here
.EXIT ; Generate exit code
END
Summary: A module must always finish with the END directive.
The .DATA and .CODE statements do not require any separate statements to define the end of a segment. They close the preceding segment and then open a new segment. The .STACK directive opens and closes the stack segment but does not close the current segment. The END statement closes the last segment and marks the end of the source code. It must be at the end of every module, whether or not it is the main module.