PURPOSE:
Use .8086 to inform MASM to allow instructions available on the 8088 and 8086 processors only. This also enables the assembly of instructions specific to the 8087 floating-point processor.
SYNTAX:
.8086
By default, MASM accepts instructions specific to the 8088, 8086, and 8087 processors only. Selecting this default instruction set
ensures that your program can run on all MS-DOS systems, but it also means that you cannot take advantage of the new and advanced
features of the 80286, 80386, 80287, 80387, 80486, 80586, etc. processors. A better solution is to detect the processor present
in the system and use the instructions for newer processors when the conditions permit.
SEE ALSO:
.8087, .NO87, .186, .286, .286P,
.287, .386, .386P, .387, .486,
.486P, .586, .586P, .686, .686P
EXAMPLE:
Normally you do not have to use the .8086 directive because it is active by default. However, if you use any 30836-specific instructions
in your program, you may want to keep them confined in a section, as shown in the following example. This way you can be certain that
all 80386-specific code is in one place because MASM generates an error message if you use them anywhere else.
; ---------- Start of 80386 specific code ----------
   .386
; all 80386 code such as 32-bit moves, bit tests, etc., go here
   movsx eax, bx ; copy BX to EAX with sign extension
   .
   .
   mov cx, 10                  ; bit number to CX
   btr WORD PTR ErrorCode, cx  ; copy bit to CF and reset
   .
   .
; ------------ End of 80386 specific code ----------
; back to plain vanilla 8086
   .8086
PURPOSE:
Use .8087 to enable assembly of instructions specific to the 8087 floating-point coprocessor and disable the assembly of
instructions for the 80287 and 80387 coprocessors. The .8087 directive also specifies the IEEE format for binary representation
of floating-point numbers.
SYNTAX:
.8087
MASM accepts 8087 instructions by default. The .8087 directive is provided so that if your program uses the instructions of all
math coprocessors (8087, 80287, 80387, 80487, etc.), you can revert back to the instruction set of 8087 when necessary.
SEE ALSO:
.8086, .NO87, .186, .286, .286P,
.287, .386, .386P, .387, .486,
.486P, .586, .586P, .686, .686P
EXAMPLE:
in the following example the .8087 directive is used after a block of 80387-specific instructions to revert back to the 8087.
; ---------- Start of 80386 specific code ----------
   .387
   fldpi      ; load "pi"
   fsin       ; take its sine
   .
   .
; ------------ End of 80386 specific code ----------
; back to plain vanilla 8087
   .8087
PURPOSE:
Use .186 to direct MASM to accept instructions specific to the 80186 processor in addition to the basic 8086 and 8087 instructions.
SYNTAX:
.186
The 80186 instruction set is a superset of the 8086 instructions. For example, the 80186 has a PUSH immediate_value
instruction which the 8086 does not allow.
SEE ALSO:
.8086, .8087, .NO87, .286, .286P,
.287, .386, .386P, .387, .486,
.486P, .586, .586P, .686, .686P
EXAMPLE:
Suppose you want to use the push instruction with an immediate operand (which is legal in processors later than the 80186).
You can do so provided you place a .186 directive before the instruction.
    .186
    push 4   ; allowed on 80186 and above
PURPOSE:
Use .286 to ask MASM to accept instructions specific to the real mode operation of the 80286 processor in addition to the basic
8086 and 80186 instructions. This also enables the assembly of 80287 instructions.
SYNTAX:
.286
The .286 directive is similar to the .286C directive in previous versions of MASM. The .286 directive disables the assembly of
protected mode instructions specific to the 80286 even if they were previously enabled with a .286P directive.
SEE ALSO:
.8086, .8087, .NO87, .186, .286P,
.287, .386, .386P, .387, .486,
.486P, .586, .586P, .686, .686P
EXAMPLE:
    .286            ; enable 80386 specific instructions
    movsx eax, bx   ; copy BX to EAX with sign extension
PURPOSE:
Use .286P to enable the assembly of instructions specific to the protected mode operation of the 80286 processor in addition to
the instructions for the 8086, 80186, and 80286 in real mode. The .286P directive also enables assembly of 80287 instructions.
SYNTAX:
.286P
The protected mode instructions are used in writing operating system software. Application programs do not use these privileged
instructions that manage multiple processors.
SEE ALSO:
.8086, .8087, .NO87, .186, .286,
.287, .386, .386P, .387, .486,
.486P, .586, .586P, .686, .686P
EXAMPLE:
    .286P        ; enable 80286's privileged instructions
    lgdt    ax   ; a privileged instruction
PURPOSE:
Use .386 to ask MASM to accept the nonprivileged instructions of the 80386 processor in addition to the basic 8086, 80186, and 80286
instructions. This also enables the assembly of 80387 instructions.
SYNTAX:
.386
The .386 directive disables the assembly of protected mode instructions specific to the 80386 even if they were previously enabled
with a .386P directive. You should use the .386 directive if your program is meant for the 80386-based system only.
SEE ALSO:
.8086, .8087, .NO87, .186, .286,
.286P, .287, .386P, .387, .486,
.486P, .586, .586P, .686, .686P
EXAMPLE:
    .386            ; enable 80386 specific instructions
    movsx eax, bx   ; copy BX to EAX with sign extension
PURPOSE:
Use .CODE to define the start of the code segment. You must select a memory model with a .MODEL directive
before using the .CODE directive. When you plan to use more than one code segment, you have to specifiy a name for each one. The
name is optional when there is only one code segment.
SYNTAX:
.CODE [name]
You should place all processor instructions in a segment initiated with the .CODE directive.
SEE ALSO:
ASSUME, SEGMENT, ENDS, .DATA,
.STACK, .MODEL
EXAMPLE:
        .MODEL SMALL       ; must precede .CODE, .DATA, or .STACK
        .CODE              ; start code segment
Start:
        mov    ax, @data
        mov    ds, ax
        mov    ax, Var1
        .                  ; other instructions
        .
        .CONST             ; segment for constants
Message DB     "Press any key to continue...$"
        .DATA              ; switch to data segment
Var1    DW     8
        .STACK 512         ; define a 512 byte stack segment
        END    Start       ; mark end of program
PURPOSE:
Use .DATA to define the start of a data segment named _DATA for initialized data. The .DATA? directive begins a data segment named _BSS
for uninitialized data. You must select a memory model with a .MODEL directive before using the .DATA and .DATA? directives.
SYNTAX:
.DATA
.DATA?
If a procedure writtne in assembly language will be called from a high-level language, you should follow the convention of placing initialized
and uninitialized data in segments defined by .DATA and .DATA?, respectively. In stand-alone assembly language programs, these segments are
not necessary. Note that the segments started by .DATA, .DATA?, .CONST, and .STACK are placed in the group named DGROUP. Thus, you should
use DGROUP to initialize the DS register when accessing in those segments.
SEE ALSO:
.CODE, .STACK, .MODEL, ASSUME,
SEGMENT, ENDS, GROUP
EXAMPLE:
See example for .CODE
PURPOSE:
Use .DOSSEG to order segments according to the convention used in MS-DOS.
SYNTAX:
DOSSEG
.DOSSEG
Segment-ordering defines how the segments are laid out in memory when the program is loaded for execution. The DOS segment-ordering
convention is alos followed by Microsoft's high-level languages such as C and FORTRAN. Since order of segments is not critical in
assembly language programs, you can safely use the .DOSSEG directive in such programs.
SEE ALSO:
.ALPHA, .SEG
EXAMPLE:
    .DOSSEG
    .MODEL SMALL
PURPOSE:
Use INCLUDE to incorporate the contents of the file named FileName into your program at the location where the INCLUDE directive
occures.
SYNTAX:
INCLUDE FileName
The file name FileName can be a full pathname. When you give a full pathname, MASM looks for the file in the specified location only.
Otherwise, MASM automatically searches for the file in the directory names specified in the /I option to MASM, the current directory, and
the directories listed in the INCLUDE environment variable, in that order. INCLUDE is often used to incorporate a standard set of macro
definitions into a program.
EXAMPLE:
    INCLUDE   mymacros.inc ; insert content of file here
    INCLUDE   c:\masm32\include\windows.inc
    INCLUDE   <\masm32\include\kernel32.inc>
PURPOSE:
Use INCLUDE to incorporate the contents of the file named FileName into your program at the location where the INCLUDE directive
occures.
SYNTAX:
INCLUDE FileName
The file name FileName can be a full pathname. When you give a full pathname, MASM looks for the file in the specified location only.
Otherwise, MASM automatically searches for the file in the directory names specified in the /I option to MASM, the current directory, and
the directories listed in the INCLUDE environment variable, in that order. INCLUDE is often used to incorporate a standard set of macro
definitions into a program.
EXAMPLE:
    INCLUDE   mymacros.inc ; insert content of file here
    INCLUDE   c:\masm32\include\windows.inc
    INCLUDE   <\masm32\include\kernel32.inc>
PURPOSE:
Use INCLUDELIB to embed information in the object file telling the linker that this module has to be linked with the library
named libname. The linker automatically searches for the library file in the current directory, the directoy names
specified in the LINK command, and the directories listed in the LIB environment variable, in that order.
SYNTAX:
INCLUDELIB libname
The information embedded in the object file by the INCLUDELIB-directive is used by the linker automatically to search the named
library file for any external references. The libname argument can only be a file name (if you omit the extension, the
default extension is LIB). Full directory pathnames are mot allowed.
If you not use INCLUDELIB and your program needs a library, you can explicitly ask the linker to search a library during linking.
The libraryname must be enclosed in angle brackets if it includes a backslash, semicolon, greater-than symbol, less-than symbol,
single quotation mark, or double quotation mark.
EXAMPLE:
Suppose your program calls routines from a library named GRAPHICS.LIB. If your program is called TESTPLOT.ASM and if it contains
the following statement, you can assemble and link the program TESTPLOT.EXE with the command ml testplot.asm graphics.lib
which specifies the name of the library explicitly.
    INCLUDELIB  graphics ; link with GRAPHICS.LIB
PURPOSE:
Use .MODEL to select a memory model before using the simplified segmentation directives available in MASM 5.0 and later. The memory
can be one of TINY, SMALL, MEDIUM, COMPACT, LARGE, HUGE, or FLAT.
SYNTAX:
.MODEL memory_model [[, langtype]] [[, stackoption]]
You use this directive in combination with the simplified segment directives. The .MODEL directive is inserted before any other
simplified segment directives appearing in your program. The required memory model operand is mainly to support assembly language
procedures that will be called by other high level languages such as C, C++, Delphi, Pascal, BASIC, Fortran, etc. For stand-alone
assembly language programs a SMALL model is usually adequate with the below exceptions.
The memory_model operand is a required parameter that determines the size of code and data pointers.
The langtype operand is an optional parameter that sets the calling and naming conventions for procedures and public symbols.
The stackoption operand is not used if memorymodel is FLAT. Also, .MODEL is not used in MASM for x64-bit (ml64.exe).
Specifying NEARSTACK groups the stack segment into a single physical segment (DGROUP) along with data. The stack segment register
(SS) is assumed to hold the same address as the data segment register (DS). FARSTACK does not group the stack with DGROUP; thus SS
does not equal DS.
The following table lists the possible values for each parameter when targeting 16-bit and 32-bit platforms:
Parameter | 32-bit values | 16-bit values (support for earlier 16-bit development) |
---|
memorymodel | FLAT | TINY , SMALL , COMPACT , MEDIUM , LARGE , HUGE , FLAT |
langtype | C , STDCALL | C , BASIC , FORTRAN , PASCAL , SYSCALL , STDCALL |
stackoption | Not used | NEARSTACK , FARSTACK |
SEE ALSO:
.CODE, .DATA, .STACK, .STARTUP,
.EXIT
EXAMPLE:
    .model flat, stdcall   ; Flat, 32-bit memory model (not used in 64-bit)
    .model small, C  
    ; In this sample, the 'X64' define excludes source not used
    ; when targeting the x64 architecture
    ifndef X64
       .686p
       .XMM
       .model flat, C
    endif
PURPOSE:
Accumulator, Low Half of AX 8-bit Register (1 Byte Size)
SYNTAX:
AL
Accumulator for operands and results data, multiply/divide, string load & store. Used in arithmetic operations.
SEE ALSO:
AX, AH
EXAMPLE:
    mov al, 10   ; move value 10 into AL
PURPOSE:
Accumulator, High Half of AX 8-bit Register (1 Byte Size)
SYNTAX:
AH
Accumulator for operands and results data, multiply/divide, string load & store. Used in arithmetic operations.
SEE ALSO:
AX, AL
EXAMPLE:
    mov ah, 10   ; move value 10 into AH
PURPOSE:
Accumulator 16-bit Register (2 Byte Size)
SYNTAX:
AX
Accumulator for operands and results data, multiply/divide, string load & store. Used in arithmetic operations.
SEE ALSO:
AL, AH
EXAMPLE:
    mov ax, 40h   ; move value 40 hex into AX
PURPOSE:
Move byte or word, original 8086/8088 instruction
SYNTAX:
MOV dest, src
Copies byte or word from the source operand to the destination operand. If the destination is SS interrupts are disabled
except on early buggy 808x CPUs. Some CPUs disable interrupts if the destination is any of the segment registers.
SEE ALSO:
AX, AH
EXAMPLE:
    mov al, 10   ; move value 10 into AL