Microsoft Macro Assembler

Microsoft Macro Assembler
Microsoft Macro Assembler
Developer(s) Microsoft
Stable release 10.0.30319.1 / April 12, 2010; 18 months ago (2010-04-12)
Operating system Microsoft Windows and MS-DOS
Type Assembler
License Microsoft EULA

The Microsoft Macro Assembler is an x86 assembler that uses the Intel syntax for Microsoft Windows. As of 2011 there was a version of the Microsoft Macro Assembler for 16-bit and 32-bit assembly sources, MASM, and a different one, ML64, for 64-bit sources only. References below to MASM include ML64 where appropriate.

MASM is maintained by Microsoft, but since version 6.12 has not been sold as a separate product, but supplied with various Microsoft SDKs and C compilers. As of 2011 MASM 8.0 was available free of charge for download from Microsoft for non-commercial use only[1]. It will only install if Visual C++ 2005 Express, also downloadable without charge, is already installed.



The earliest versions of MASM date back to 1981. [2]

Up to version 5.0, MASM was available as an MS-DOS application only. Versions 5.1 and 6.0 were available as both MS-DOS and OS/2 applications.[3]

Version 6.0, released in 1992, added high-level programming support and a more C-like syntax. By the end of the year, version 6.1A updated the memory management to be compatible with code produced by Visual C++. In 1993 full support for 32-bit applications and the Pentium instruction set was added. The MASM binary at that time was shipped as a "bi-modal" DOS-extended binary (using the Phar Lap TNT DOS extender).

Versions 6.12 to 6.14 were implemented as patches for version 6.11. These patches changed the type of the binary to native PE format; version 6.11 is the last version of MASM that will run under MS-DOS.

By the end of 1997 MASM fully supported Windows 95 and included some AMD-specific instructions.[4]

In 1999 Intel released macros for SIMD and MMX instructions, which were shortly after supported natively by MASM. With the 6.15 release in 2000, Microsoft discontinued support for MASM as a separate product, instead subsuming it into the Visual Studio toolset. Though it was still compatible with Windows 98, current versions of Visual Studio were not.[4] Support for 64-bit processors was not added until the release of Visual Studio 2005, with MASM given the version number 8.0.

MASM assembly language details

MASM has been the main vehicle for preserving the earlier Intel assembler notation and it can still be written as a fully specified language, a format that many disassemblers produce.

The OFFSET operator

If a data label is referenced in an expression, MASM will generally assume that the content of the memory reference is to be targeted. To access the address and not the content of a data label, MASM supplies addditional operators - OFFSET and SEG - to tell the assembler the different intention:

   mov eax, data_label       ; load the content of data_label ( assumed DWORD here )
   mov eax, OFFSET data_label; load the address ( the offset part of it ) of data_label

The OFFSET operator is not required to get the address of code labels; it is accepted, but ignored.

Square bracket operator []

The square bracket operator behaves differently depending on the context. For direct addressing, the square brackets are similar to the + operator. As a result, square brackets around a data label have no effect:

   mov eax, local_var     ; Standard MASM notation
   mov eax, [local_var]   ; Square brackets won't change semantics here.

However, if the square brackets are used to enclose general purpose registers (GPR), the operator has a different meaning: now it is indicating that the register(s) enclosed is/are to be used as base or index register(s) for indirect memory addressing.

   mov eax, [eax]            ; dereference the CONTENT of the variable and copy it into the EAX register.

Type coercion with the PTR operator

MASM's built-in PTR operator may be used to a) set a type for an "untyped" memory reference or b) override the type for a data label. The semantics are quite similar to C typecasts.

   movzx eax, [esi]             ; This fails as the assembler cannot determine the size of data to be zero extended into the EAX register.
movzx eax, BYTE PTR [esi] ; this is the correct notation if the programmer wishes to zero extend a BYTE into a 32 bit register. mov ax, WORD PTR byte_label ; override the type of a variable

Argument type checking

From at least version 6.0, MASM has supported a high-level notation for creating procedures that perform argument size and count checking. It is part of a system using the PROC ENDP PROTO and INVOKE directives. The PROTO directive is used to define prototypes, PROC/ENDP pairs define so-called procedures. Both can then be called with the INVOKE directive, which includes argument size and argument count checking. Using those directives is optional.

Using an example prototype from the 32 bit Windows API function set,

   SendMessage equ <SendMessageA>

The code to call this function using the INVOKE notation is as follows.

   invoke SendMessage,hWin,WM_COMMAND,wParam,lParam

Which is translated exactly to,

   push lParam
   push wParam
   push WM_COMMAND
   push hWin
   call SendMessage

The 64-bit version of MASM (ML64) did not as of 2011 support INVOKE.

Calling conventions

MASM supports a number of different calling conventions on both the 16 bit real mode DOS operating system, the 16 bit Windows versions and the later 32 bit versions. MASM supports the C, SYSCALL, STDCALL, BASIC, FORTRAN and PASCAL calling conventions.[5]

High-level control loops

MASM provides a notation to emulate a variety of high level control and loop structures.
It supports the .IF block structure,


It also supports the .WHILE loop structure,

 .while eax > 0
   sub eax, 1

And the .REPEAT loop structure.

   sub eax, 1
 .until eax < 1

The high level emulation also supports C runtime comparison operators that work according to the same rules as Intel mnemonic comparisons.[6]

The 64-bit version of Masm (ML64) does not support these features.


MASM has a very powerful preprocessor that has considerably more functionality than C preprocessors. The MASM preprocessor is an integral part of the assembler and hence has access to the assembler's symbol table and expression evaluator. Seen from the outside, the preprocessor consists of

  • assembly-time conditional directives IF, IFDEF, IFB, IFIDN, ...
  • string manipulation and query directives CATSTR, SUBSTR, INSTR, ...
  • assembly-time loop directives REPEAT, WHILE, FOR, FORC,...
  • MACRO, EXITM and GOTO directives
  • operators, i.e. OPATTR, that allows to detect a symbol's type at assembly-time.

Using the EXITM <return item> notation a macro can return a value or register in a way that can be used similar to a function call. A very simple example:

   addregs32 MACRO reg1, reg2
     add reg1, reg2
     EXITM <reg1>
   ;--- now "calling" macro addregs32
   mov ecx, 16
   mov edx, 8
   mov eax, addregs32(ecx, edx)

Object module formats supported by MASM

Early versions of MASM generated object modules using the OMF format, which was used to create binaries for MS-DOS or OS/2.

Since version 6, MASM is able to produce object modules in the Portable Executable[7][8] (PE/COFF) format. PE/COFF is compatible with recent Microsoft C compilers, and object modules produced by either MASM or the C compiler can be routinely intermixed and linked into Win32 and Win64 binaries.

Some third-party tools that support MASM




Assemblers compatible with MASM

Some other assemblers can assemble most code written for MASM, with the exception of more complex macros.

  • Pelle's Macro Assembler, a component of the Pelles C development environment.
  • JWASM Macro Assembler, licenced under the Sybase Open Watcom EULA.
  • Turbo Assembler (TASM) developed by Borland, later owned by Embarcadero, last updated in 2002 and supplied with Delphi and C++Builder for several years, later discontinued.

See also


External links

Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Microsoft Macro Assembler — (MASM, макроассемблер Microsoft)  ассемблер для процессоров семейства x86. Первоначально был произведён компанией Microsoft для написания программ в операционной системы MS DOS и был в течение некоторого времени самым популярным ассемблером …   Википедия

  • Microsoft Macro Assembler — Der Microsoft Macro Assembler (abgekürzt MASM) ist ein von Microsoft entwickelter Assembler für x86 basierende Prozessoren. Er übersetzt Assemblerquelltext in ausführbaren, nativen Maschinencode. Der Microsoft Macro Assembler entwickelte sich… …   Deutsch Wikipedia

  • Microsoft Macro Assembler — Le logiciel Microsoft Macro Assembler (Macro Assembleur de Microsoft, plus connu sous l acronyme MASM) est un assembleur pour la famille de processeurs x86. Il fut à l origine développé par Microsoft pour le développement de leur système d… …   Wikipédia en Français

  • Microsoft Macro Assembler — El Microsoft Macro Assembler (MASM) es un ensamblador para la familia x86 de microprocesadores. Fue producido originalmente por Microsoft para el trabajo de desarrollo en su sistema operativo MS DOS, y fue durante cierto tiempo el ensamblador más …   Wikipedia Español

  • Microsoft Assembler — Der Microsoft Macro Assembler (abgekürzt MASM) ist ein von Microsoft entwickelter Assembler für x86 basierende Prozessoren. Er übersetzt Assemblerquelltext in ausführbaren, nativen Maschinencode. Der Microsoft Macro Assembler entwickelte sich… …   Deutsch Wikipedia

  • Macro — Para la fotografía, véase Macrofotografía. Para el museo, véase Museo de Arte Contemporáneo de Rosario. Una macro (del griego μακρο; significa «grande»), abreviatura de macroinstrucción, es una serie de instrucciones que se almacenan para que se… …   Wikipedia Español

  • Assembler-Code — Eine Assemblersprache ist eine spezielle Programmiersprache, welche die Maschinensprache einer spezifischen Prozessorarchitektur in einer für den Menschen lesbaren Form repräsentiert. Jede Computerarchitektur hat folglich ihre eigene… …   Deutsch Wikipedia

  • Assembler (Informatik) — Ein Assembler (nach DIN 44300: Assemblierer) ist ein Hilfsprogramm der Programmierung (Programmierwerkzeug), das ein in maschinennaher Assemblersprache geschriebenes Computerprogramm in Maschinensprache (auch Maschinencode oder Nativer Code… …   Deutsch Wikipedia

  • Macro (computer science) — A macro (from the Greek μάκρο for long or far) in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to an output sequence (also often a sequence of characters)… …   Wikipedia

  • Macro — Makro stammt aus dem Griechischen (μακρος makros) und bedeutet „groß“ oder „weit“. Unter einem Makro versteht man ein Programm, das eine fest vorgegebene Folge von Befehlen, Aktionen oder Tastaturcodes enthält. Alle Anweisungen des Makros werden… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”

We are using cookies for the best presentation of our site. Continuing to use this site, you agree with this.