.MODEL

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at .MODEL.

Initializes the program memory model.

.MODEL memorymodel [[, langtype]] [[, stackoption]]  

Parameters

memorymodel
Required parameter that determines the size of code and data pointers.

langtype
Optional parameter that sets the calling and naming conventions for procedures and public symbols.

stackoption
Optional parameter.

stackoption is not used if memorymodel is FLAT.

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.

.MODEL is not used in MASM for x64 (ml64.exe).

The following table lists the possible values for each parameter when targeting 16-bit and 32-bit platforms:

Parameter32-bit values16-bit values (support for earlier 16-bit development)
memorymodelFLATTINY, SMALL, COMPACT, MEDIUM, LARGE, HUGE, FLAT
langtypeC, STDCALLC, BASIC, FORTRAN, PASCAL, SYSCALL, STDCALL
stackoptionNot usedNEARSTACK, FARSTACK

For MASM-related samples, download the Compiler samples from Visual C++ Samples and Related Documentation for Visual Studio 2010.

The following example demonstrates the use of the .MODEL directive.

; file simple.asm  
; For x86 (32-bit), assemble with debug information:   
;   ml -c -Zi simple.asm  
; For x64 (64-bit), assemble with debug information:   
;   ml64 -c -DX64 -Zi simple.asm  
;  
; In this sample, the 'X64' define excludes source not used   
;  when targeting the x64 architecture  
  
ifndef X64  
.686p  
.XMM  
.model flat, C  
endif  
  
.data  
; user data  
  
.code  
; user code  
  
fxn PROC public  
  xor eax, eax ; zero function return value  
  ret  
fxn ENDP  
  
end  

Directives Reference
Visual C++ Samples and Related Documentation for Visual Studio 2010

Show: