<<< | Index | The .MODEL directive >>> |
MASM programs consist of file modules made up of segments.
Logical segments contain the three components of a program: code, data, and stack.
MASM organizes all three logical segments for you, so they occupy physical segments of memory at runtime.
Segment registers CS, DS, and SS contain either physical memory segments (real mode), or logical segments (protected mode).
Simplified segment directives hide many of the details of segment definition and assume the same conventions as are used by Microsoft high-level languages.
The simplified segment directives are .MODEL, .CODE, .CONST, .DATA, .DATA?, .FARDATA, .FARDATA?, and .STACK.
Every program written only in MASM has one main module, where program execution begins.
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 begin with the .MODEL directive.
Example of a minimal main module using simplified segment directive structure is this:
; your_program_name.asm ; Brief description of what program does .586P ; Enable assembly of all Pentium instructions, ; including privileged. .MODEL FLAT, STDCALL ; Change calling convention, if necessary. ; MODEL directive is required before ; other simplified segment directives. .STACK ; Use default 1-kilobyte stack .DATA ; Begin data segment ; Put your data declarations here .CODE ; Begin code segment _start: ; Start of main program code ; Put your main application code here ret ; Exit program PUBLIC _start ; Make entry point public ; Put your application procedures here END
The .DATA and .CODE statements do not require any separate statements to define the end of a segment.
.DATA and .CODE close the preceding segment and then open a new segment.
The .STACK sizeoptional directive opens and closes the stack segment (with segment name STACK). Directive does not close the current segment. Default stack size is 1024.
The END statement closes the last segment and marks the end of the source code. It must be at the end of every module.
The .STARTUP and .EXIT directives are available only in 16-bit addressing modes:
. .CODE ; Begin code segment .STARTUP ; Generate start-up code (not for 32-bit segments) ; Put your main application code here .EXIT ; Generate termination code (not for 32-bit segments) ; Put your application procedures here END
<<< | Index | The .MODEL directive >>> |