- Microsoft Macro Assembler
-
Microsoft Macro Assembler Developer(s) Microsoft Stable release 10.0.30319.1 / April 12, 2010 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[update] 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[update] 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.
Contents
History
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 PROTO STDCALL :DWORD,:DWORD,:DWORD,:DWORD 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[update] 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,.if - .elseif - .else - .endif
It also supports the .WHILE loop structure,
.while eax > 0 sub eax, 1 .endw
And the .REPEAT loop structure.
.repeat 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.
Preprocessor
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> ENDM ;--- 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
IDEs
- Microsoft Visual Studio
- RadASM[9]
- WinAsm Studio[10]
- EasyCode[11]
Debuggers
- OllyDbg[12]
Disassemblers
- IDAPro the Interactive Disassembler
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
- Assemblers
- High-level assembler
- Comparison of assemblers
Footnotes
- ^ MASM download page from Microsoft, non-commercial use only
- ^ Watt, Peggy; Christine McGeever (January 7, 1985). "Macintosh Vs. IBM PC At One Year". InfoWorld 7 (1): pp. 15–16. ISSN 0199-6649. http://books.google.com/books?id=-i4EAAAAMBAJ&pg=PA16. The IBM PC Macro Assembler was released in December 1981.
- ^ Marshall, Martin (April 29, 1991). "Macro Assembler Update Adds High-Level Features". InfoWorld 13 (17): p. 21. ISSN 0199-6649. http://books.google.com/books?id=y1AEAAAAMBAJ&pg=PT20.
- ^ a b R. E. Harvey (2007). "Assemblers". Archived from the original on 16 February 2008. http://web.archive.org/web/20080216121237/http://ourworld.compuserve.com/homepages/r_harvey/doc_book.htm. Retrieved 4 February 2010.
- ^ ALANG.HLP standard installation Masm 6.11d
- ^ http://www.intel.com/products/processor/manuals/
- ^ http://download.microsoft.com/download/e/b/a/eba1050f-a31d-436b-9281-92cdfeae4b45/pecoff.doc
- ^ http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
- ^ http://radasm.cherrytree.at/
- ^ http://www.winasm.net/
- ^ http://www.easycode.cat/English/index.htm
- ^ http://www.ollydbg.de/
External links
- Official Microsoft Macro Assembler Reference
- Intro to MASM Win32
- Win32 assembly tutorials using MASM
x86 assembly topics Topics x86 Assemblers Programming issues Categories:- Assemblers
- Microsoft development tools
- DOS software
- Windows software
Wikimedia Foundation. 2010.