You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For information on instruction definitions, options, and encoding, see the [Processor Manufacturer Programming Manuals](../../assembler/masm/processor-manufacturer-programming-manuals.md). Some instructions and instruction options may not be supported by the Microsoft Macro Assembler.
17
+
18
+
## Prefix
19
+
20
+
You can prefix some instructions with keywords that set options for how the instruction is encoded. The **`REP`**, **`REPE`**, **`REPZ`**, **`REPNE`**, and **`REPNZ`** keywords are used with string instructions to do `memcpy` or `strlen` kinds of operations in a single instruction. The **`LOCK`** keyword makes certain operations on memory operands atomic. You can combine it with the **`XACQUIRE`** and **`XRELEASE`** keywords to do Hardware Lock Elision (HLE) on supported processors, which allows greater transactional parallelism in certain cases.
21
+
22
+
The remaining prefixes control how AVX instructions are encoded. AVX instructions are encoded using a **`VEX`** prefix, which appears before the opcode. It takes the place of certain byte instruction prefixes and opcode lead-in bytes. Many AVX instructions are also AVX-512 instructions, which are encoded using an **`EVEX`** prefix that supports [more options](#avx-512-options). MASM tries to encode instructions as compactly as possible, but these keywords allow more control over which encoding to use with a particular instruction. They're also used to force generation of AVX instruction forms that were introduced after the corresponding AVX-512 instruction. For example, `vex vpdpbusd` specifies the AVX-VNNI form of the `VPDPBUSD` instructions rather than the AVX512-VNNI form. When an AVX instruction appears without an explicit prefix keyword, the encoding chosen depends on the current AVX encoding setting. The [`OPTION AVXENCODING`](option-avxencoding-masm.md) directive lets you change this setting.
23
+
24
+
The **`VEX2`**, **`VEX3`**, **`VEX`**, and **`EVEX`** options are available in Visual Studio 2019 version 16.7 and later.
25
+
26
+
| Keyword | Usage |
27
+
|--|--|
28
+
|**`REP`**| Repeat the string operation by the count in (E)CX. |
29
+
|**`REPE`**| Repeat the string operation while the comparison is equal, limited by the count in (E)CX. |
30
+
|**`REPE`**| Repeat the string operation while the comparison is not-equal, limited by the count in (E)CX. |
31
+
|**`LOCK`**| Perform the operation atomically on a memory operand. |
32
+
|**`XACQUIRE`**| Begin an HLE transaction, most often used with **`LOCK`** prefix. |
33
+
|**`XRELEASE`**| Complete an HLE transaction, most often used with **`LOCK`** prefix. |
34
+
|**`VEX`**| Encode an AVX instruction using a **`VEX`** prefix. |
35
+
|**`VEX2`**| Encode an AVX instruction using a 2-byte **`VEX`** prefix. |
36
+
|**`VEX3`**| Encode an AVX instruction using a 3-byte **`VEX`** prefix. |
37
+
|**`EVEX`**| Encode an AVX instruction using an **`EVEX`** prefix. |
38
+
39
+
## Mnemonic
40
+
41
+
The mnemonic identifies a particular instruction, which determines the prefixes and operand patterns that are allowed.
42
+
43
+
## Operand list
44
+
45
+
Most instructions use an operand list to specify the explicit source and destination operands to the instruction. The operand list may contain memory references, registers, and constant values. Each instruction allows only certain types of operands to appear at each position in the operand list. Except for the `MOVS` and `CMPS` instructions, only one of the operands may be a memory reference; all other operands must be register references or constants.
46
+
47
+
## AVX-512 options
48
+
49
+
Some AVX-512 instructions allow more options to be specified. These options are: masking, zero-masking, embedded broadcast, embedded rounding, and exception suppression.
50
+
51
+
*Masking* allows an operation to be applied only to selected elements of a vector. This option is controlled by placing a mask register from `{k1}` to `{k7}` after the destination operand. If the mask register is followed by `{z}`, all non-selected elements of the destination are set to zero. This alternative is known as *zero-masking*.
52
+
53
+
*Embedded Broadcast* allows a scalar value in memory to be applied to all elements of a vector. This option is enabled by adding the element size and the keyword `BCST` to the memory operand, which is similar to the use of `PTR` for normal memory references.
54
+
55
+
*Embedded Rounding* controls the rounding mode for an individual floating-point instruction, without having to set and reset the global rounding mode. It's enabled by following the instruction with the rounding mode enclosed in braces. When enabled, it also suppresses all exceptions for only that instruction. Floating-point instructions that don't round can also suppress all exceptions using a similar option.
Copy file name to clipboardExpand all lines: docs/assembler/masm/masm-for-x64-ml64-exe.md
+18-18Lines changed: 18 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,23 @@
1
1
---
2
-
description: "Learn more about: MASM for x64 (ml64.exe)"
2
+
description: "Learn more about: Microsoft Macro Assembler (MASM) for x64 (ml64.exe)"
3
3
title: "MASM for x64 (ml64.exe)"
4
-
ms.date: "12/17/2019"
4
+
ms.date: 09/21/2021
5
5
helpviewer_keywords: ["ml64", "ml64.exe", "masm for x64"]
6
6
ms.assetid: 89059103-f372-4968-80ea-0c7f90bb9c91
7
7
---
8
8
# MASM for x64 (ml64.exe)
9
9
10
-
Visual Studio includes both 32-bit and 64-bit hosted versions of Microsoft Assembler (MASM) to target x64 code. Named ml64.exe, this is the assembler that accepts x64 assembler language. The MASM command-line tools are installed when you choose a C++ workload during Visual Studio installation. The MASM tools are not available as a separate download. For instructions on how to download and install a copy of Visual Studio, see [Install Visual Studio](/visualstudio/install/install-visual-studio). If you do not want to install the complete Visual Studio IDE, but only want the command-line tools, download the [Build Tools for Visual Studio](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019).
10
+
Visual Studio includes both 32-bit and 64-bit hosted versions of MASM (the Microsoft Macro Assembler) to target x64 code. Named ml64.exe, it's the assembler that accepts x64 assembler language. The MASM command-line tools are installed when you choose a C++ workload during Visual Studio installation. The MASM tools aren't available as a separate download. For instructions on how to download and install a copy of Visual Studio, see [Install Visual Studio](/visualstudio/install/install-visual-studio). If you only want the command-line tools, not the full IDE, download the [Build Tools for Visual Studio](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019).
11
11
12
-
To use MASM to build code for x64 targets on the command line, you must use a developer command prompt for x64 targets, which sets the required path and other environment variables. For information on how to start a developer command prompt, see [Build C/C++ code on the command line](../../build/building-on-the-command-line.md).
12
+
To use ml64.exe on the command line, start a developer command prompt for x64 targets. A developer command prompt sets the required path and other environment variables. For information on how to start a developer command prompt, see [Build C/C++ code on the command line](../../build/building-on-the-command-line.md).
13
13
14
-
For information on ml64.exe commandline options, see [ML and ML64 Command-Line Reference](ml-and-ml64-command-line-reference.md).
14
+
For information on ml64.exe command-line options, see [ML and ML64 Command-Line Reference](ml-and-ml64-command-line-reference.md).
15
15
16
-
Inline assembler or use of the ASM keyword is not supported for x64 or ARM targets. To port your x86 code that uses inline assembler to x64 or ARM, you can convert your code to C++, use compiler intrinsics, or create assembler-language source files. The Microsoft C++ compiler supports intrinsics to allow you to use special-function instructions, for example, privileged, bit scan/test, interlocked, and so on, in as close to a cross-platform manner as possible. For information on available intrinsics, see [Compiler Intrinsics](../../intrinsics/compiler-intrinsics.md).
16
+
Inline assembler or use of the **`ASM`** keyword isn't supported for x64 or ARM64 targets. To port your x86 code that uses inline assembler to x64 or ARM64, you can convert your code to C++, use compiler intrinsics, or create assembler-language source files. The Microsoft C++ compiler supports intrinsics to allow you to use special-function instructions, for example, privileged, bit scan or test, interlocked, and so on, in as close to a cross-platform manner as possible. For information on available intrinsics, see [Compiler Intrinsics](../../intrinsics/compiler-intrinsics.md).
17
17
18
18
## Add an assembler-language file to a Visual Studio C++ project
19
19
20
-
The Visual Studio project system supports assembler-language files built by using MASM in your C++ projects. You can create x64 assembler-language source files and build them into object files by using MASM, which supports x64 fully. You can then link these object files to your C++ code built for x64 targets. This is one way to overcome the lack of an x64 inline assembler.
20
+
The Visual Studio project system supports assembler-language files built by using MASM in your C++ projects. MASM fully supports x64 assembler-language source files, and builds them into object files. You can then link these object files to your C++ code built for x64 targets. It's one way to overcome the lack of an x64 inline assembler.
21
21
22
22
### To add an assembler-language file to an existing Visual Studio C++ project
23
23
@@ -27,29 +27,29 @@ The Visual Studio project system supports assembler-language files built by usin
27
27
28
28
1. On the menu bar, choose **Project**, **Add New Item**.
29
29
30
-
1. In the **Add New Item** dialog box, select **C++ file (.cpp)** in the center pane. In the **Name** edit control, enter a new file name that has a **.asm** extension instead of .cpp. Choose **Add** to add the file to your project and close the dialog box.
30
+
1. In the **Add New Item** dialog box, select **C++ file (.cpp)** in the center pane. In the **Name** edit control, enter a new file name that has a *`.asm`* extension instead of *`.cpp`*. Choose **Add** to add the file to your project and close the dialog box.
31
31
32
-
Create your assembler-language code in the .asm file you added. When you build your solution, the MASM assembler is invoked to assemble the .asm file into an object file that is then linked into your project. To make symbol access easier, declare your assembler functions as `extern "C"` in your C++ source code, rather than using the C++ name decoration conventions in your assembler-language source files.
32
+
Create your assembler-language code in the *`.asm`* file you added. When you build your solution, the MASM assembler is invoked to assemble the *`.asm`* file into an object file that is then linked into your project. To make symbol access easier, declare your assembler functions as `extern "C"` in your C++ source code, rather than using the C++ name decoration conventions in your assembler-language source files.
33
33
34
34
## ml64-Specific Directives
35
35
36
36
You can use the following ml64-specific directives in your assembler-language source code that targets x64:
37
37
38
-
-[.ALLOCSTACK](dot-allocstack.md)
38
+
-[`.ALLOCSTACK`](dot-allocstack.md)
39
39
40
-
-[.ENDPROLOG](dot-endprolog.md)
40
+
-[`.ENDPROLOG`](dot-endprolog.md)
41
41
42
-
-[.PUSHFRAME](dot-pushframe.md)
42
+
-[`.PUSHFRAME`](dot-pushframe.md)
43
43
44
-
-[.PUSHREG](dot-pushreg.md)
44
+
-[`.PUSHREG`](dot-pushreg.md)
45
45
46
-
-[.SAVEREG](dot-savereg.md)
46
+
-[`.SAVEREG`](dot-savereg.md)
47
47
48
-
-[.SAVEXMM128](dot-savexmm128.md)
48
+
-[`.SAVEXMM128`](dot-savexmm128.md)
49
49
50
-
-[.SETFRAME](dot-setframe.md)
50
+
-[`.SETFRAME`](dot-setframe.md)
51
51
52
-
In addition, the [PROC](proc.md) directive has been updated for use with ml64.exe.
52
+
The [`PROC`](proc.md) directive has also been updated for use with ml64.exe.
53
53
54
54
## 32-Bit Address Mode (Address Size Override)
55
55
@@ -63,7 +63,7 @@ prefetch [eax]
63
63
movnti rax, QWORD PTR [r8d]
64
64
```
65
65
66
-
MASM assumes that if a 32-bit displacement appears alone as a memory operand, 64-bit addressing is intended. There is currently no support for 32-bit addressing with such operands.
66
+
MASM assumes 64-bit addressing if a 32-bit displacement appears alone as a memory operand. There's currently no support for 32-bit addressing with such operands.
67
67
68
68
Finally, mixing register sizes within a memory operand, as demonstrated in the following code, generates an error.
The Microsoft Macro Assembler (MASM) provides several advantages over inline assembly. MASM contains a macro language that has features such as looping, arithmetic, and text string processing. MASM also gives you greater control over the hardware because it supports the instruction sets of the 386, 486, and Pentium processors. By using MASM, you also can reduce time and memory overhead.
9
+
The Microsoft Macro Assembler (MASM) provides several advantages over inline assembly. MASM contains a macro language that has features such as looping, arithmetic, and text string processing. MASM gives you greater control over the hardware. By using MASM, you also can reduce time and memory overhead in your code.
11
10
12
11
## In This Section
13
12
14
13
[ML and ML64 command-line option](ml-and-ml64-command-line-reference.md)\
15
-
Describes the ML.exe and ML64.exe command-line options.
14
+
Describes the ML and ML64 command-line options.
16
15
17
-
[ML error messages](ml-error-messages.md)\
18
-
Describes ML.exe fatal and nonfatal error messages and warnings.
16
+
[MASM for x64 (ml64.exe)](masm-for-x64-ml64-exe.md)\
17
+
Information about how to create output files for x64.
18
+
19
+
[Instruction Format](instruction-format.md)\
20
+
Describes basic instruction format and instruction prefixes for MASM.
19
21
20
22
[Directives reference](directives-reference.md)\
21
23
Provides links to articles that discuss the use of directives in MASM.
@@ -26,11 +28,11 @@ Provides links to articles that discuss the use of symbols in MASM.
26
28
[Operators Reference](operators-reference.md)\
27
29
Provides links to articles that discuss the use of operators in MASM.
0 commit comments