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
Bulk fix: Remainder of keyword style fixes (#3011)
* C++ keyword style rationalization
* Add some Microsoft-specific keywords
* Update single-tick keywords
* Add the bold keywords up to code_seg
* Last set of keywords
A great convenience of inline assembly is the ability to refer to C or C++ variables by name. An `__asm` block can refer to any symbols, including variable names, that are in scope where the block appears. For instance, if the C variable `var` is in scope, the instruction
11
+
A great convenience of inline assembly is the ability to refer to C or C++ variables by name. An **`__asm`** block can refer to any symbols, including variable names, that are in scope where the block appears. For instance, if the C variable `var` is in scope, the instruction
12
12
13
13
```cpp
14
14
__asm mov eax, var
15
15
```
16
16
17
17
stores the value of `var` in EAX.
18
18
19
-
If a class, structure, or union member has a unique name, an `__asm` block can refer to it using only the member name, without specifying the variable or `typedef` name before the period (**.**) operator. If the member name is not unique, however, you must place a variable or `typedef` name immediately before the period operator. For example, the structure types in the following sample share `same_name` as their member name:.
19
+
If a class, structure, or union member has a unique name, an **`__asm`** block can refer to it using only the member name, without specifying the variable or **`typedef`** name before the period (**.**) operator. If the member name is not unique, however, you must place a variable or **`typedef`** name immediately before the period operator. For example, the structure types in the following sample share `same_name` as their member name:.
helpviewer_keywords: ["__asm keyword [C++], vs. asm blocks", "__asm keyword [C++]"]
6
6
ms.assetid: 77ff3bc9-a492-4b5e-85e1-fa4e414e79cd
7
7
---
8
-
# __asm
8
+
# `__asm`
9
9
10
10
**Microsoft Specific**
11
11
12
-
The `__asm` keyword invokes the inline assembler and can appear wherever a C or C++ statement is legal. It cannot appear by itself. It must be followed by an assembly instruction, a group of instructions enclosed in braces, or, at the very least, an empty pair of braces. The term "`__asm` block" here refers to any instruction or group of instructions, whether or not in braces.
12
+
The **`__asm`** keyword invokes the inline assembler and can appear wherever a C or C++ statement is legal. It cannot appear by itself. It must be followed by an assembly instruction, a group of instructions enclosed in braces, or, at the very least, an empty pair of braces. The term "**`__asm`** block" here refers to any instruction or group of instructions, whether or not in braces.
13
13
14
14
> [!NOTE]
15
-
> Visual C++ support for the Standard C++ `asm` keyword is limited to the fact that the compiler will not generate an error on the keyword. However, an `asm` block will not generate any meaningful code. Use `__asm` instead of `asm`.
15
+
> Visual C++ support for the Standard C++ **`asm`** keyword is limited to the fact that the compiler will not generate an error on the keyword. However, an **`asm`** block will not generate any meaningful code. Use **`__asm`** instead of **`asm`**.
If used without braces, the `__asm` keyword means that the rest of the line is an assembly-language statement. If used with braces, it means that each line between the braces is an assembly-language statement. For compatibility with previous versions, `_asm` is a synonym for `__asm`.
29
+
If used without braces, the **`__asm`** keyword means that the rest of the line is an assembly-language statement. If used with braces, it means that each line between the braces is an assembly-language statement. For compatibility with previous versions, **`_asm`** is a synonym for **`__asm`**.
30
30
31
-
Since the `__asm` keyword is a statement separator, you can put assembly instructions on the same line.
31
+
Since the **`__asm`** keyword is a statement separator, you can put assembly instructions on the same line.
32
32
33
33
Before Visual Studio 2005, the instruction
34
34
@@ -40,11 +40,11 @@ did not cause native code to be generated when compiled with **/clr**; the compi
40
40
41
41
`__asm int 3` now results in native code generation for the function. If you want a function to cause a break point in your code and if you want that function compiled to MSIL, use [__debugbreak](../../intrinsics/debugbreak.md).
42
42
43
-
For compatibility with previous versions, **_asm** is a synonym for **__asm** unless compiler option [/Za \(Disable language extensions)](../../build/reference/za-ze-disable-language-extensions.md) is specified.
43
+
For compatibility with previous versions, **`_asm`** is a synonym for **`__asm`** unless compiler option [/Za \(Disable language extensions)](../../build/reference/za-ze-disable-language-extensions.md) is specified.
44
44
45
45
## Example
46
46
47
-
The following code fragment is a simple `__asm` block enclosed in braces:
47
+
The following code fragment is a simple **`__asm`** block enclosed in braces:
48
48
49
49
```cpp
50
50
__asm {
@@ -54,23 +54,23 @@ __asm {
54
54
}
55
55
```
56
56
57
-
Alternatively, you can put `__asm` in front of each assembly instruction:
57
+
Alternatively, you can put **`__asm`** in front of each assembly instruction:
58
58
59
59
```cpp
60
60
__asm mov al, 2
61
61
__asm mov dx, 0xD007
62
62
__asm out dx, al
63
63
```
64
64
65
-
Because the `__asm` keyword is a statement separator, you can also put assembly instructions on the same line:
65
+
Because the **`__asm`** keyword is a statement separator, you can also put assembly instructions on the same line:
66
66
67
67
```cpp
68
68
__asm mov al, 2 __asm mov dx, 0xD007 __asm out dx, al
69
69
```
70
70
71
-
All three examples generate the same code, but the first style (enclosing the `__asm` block in braces) has some advantages. The braces clearly separate assembly code from C or C++ code and avoid needless repetition of the `__asm` keyword. Braces can also prevent ambiguities. If you want to put a C or C++ statement on the same line as an `__asm` block, you must enclose the block in braces. Without the braces, the compiler cannot tell where assembly code stops and C or C++ statements begin. Finally, because the text in braces has the same format as ordinary MASM text, you can easily cut and paste text from existing MASM source files.
71
+
All three examples generate the same code, but the first style (enclosing the **`__asm`** block in braces) has some advantages. The braces clearly separate assembly code from C or C++ code and avoid needless repetition of the **`__asm`** keyword. Braces can also prevent ambiguities. If you want to put a C or C++ statement on the same line as an **`__asm`** block, you must enclose the block in braces. Without the braces, the compiler cannot tell where assembly code stops and C or C++ statements begin. Finally, because the text in braces has the same format as ordinary MASM text, you can easily cut and paste text from existing MASM source files.
72
72
73
-
Unlike braces in C and C++, the braces enclosing an `__asm` block don't affect variable scope. You can also nest `__asm` blocks; nesting does not affect variable scope.
73
+
Unlike braces in C and C++, the braces enclosing an **`__asm`** block don't affect variable scope. You can also nest **`__asm`** blocks; nesting does not affect variable scope.
Instructions in an `__asm` block can use assembly-language comments:
11
+
Instructions in an **`__asm`** block can use assembly-language comments:
12
12
13
13
```cpp
14
14
__asm mov ax, offset buff ; Load address of buff
15
15
```
16
16
17
-
Because C macros expand into a single logical line, avoid using assembly-language comments in macros. (See [Defining __asm Blocks as C Macros](../../assembler/inline/defining-asm-blocks-as-c-macros.md).) An `__asm` block can also contain C-style comments; for more information, see [Using C or C++ in __asm Blocks](../../assembler/inline/using-c-or-cpp-in-asm-blocks.md).
17
+
Because C macros expand into a single logical line, avoid using assembly-language comments in macros. (See [Defining __asm Blocks as C Macros](../../assembler/inline/defining-asm-blocks-as-c-macros.md).) An **`__asm`** block can also contain C-style comments; for more information, see [Using C or C++ in __asm Blocks](../../assembler/inline/using-c-or-cpp-in-asm-blocks.md).
An `__asm` block can call only global C++ functions that are not overloaded. If you call an overloaded global C++ function or a C++ member function, the compiler issues an error.
11
+
An **`__asm`** block can call only global C++ functions that are not overloaded. If you call an overloaded global C++ function or a C++ member function, the compiler issues an error.
12
12
13
-
You can also call any functions declared with **extern "C"** linkage. This allows an `__asm` block within a C++ program to call the C library functions, because all the standard header files declare the library functions to have **extern "C"** linkage.
13
+
You can also call any functions declared with **extern "C"** linkage. This allows an **`__asm`** block within a C++ program to call the C library functions, because all the standard header files declare the library functions to have **extern "C"** linkage.
Although an `__asm` block can reference C or C++ data types and objects, it cannot define data objects with MASM directives or operators. Specifically, you cannot use the definition directives **DB**, `DW`, **DD**, `DQ`, `DT`, and `DF`, or the operators `DUP` or **THIS**. MASM structures and records are also unavailable. The inline assembler doesn't accept the directives `STRUC`, `RECORD`, **WIDTH**, or **MASK**.
11
+
Although an **`__asm`** block can reference C or C++ data types and objects, it cannot define data objects with MASM directives or operators. Specifically, you cannot use the definition directives **DB**, `DW`, **DD**, `DQ`, `DT`, and `DF`, or the operators `DUP` or **THIS**. MASM structures and records are also unavailable. The inline assembler doesn't accept the directives `STRUC`, `RECORD`, **WIDTH**, or **MASK**.
Copy file name to clipboardExpand all lines: docs/assembler/inline/debugging-and-listings-for-inline-assembly.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Programs containing inline assembly code can be debugged with a source-level deb
12
12
13
13
Within the debugger, you can set breakpoints on both C or C++ and assembly-language lines. If you enable mixed assembly and source mode, you can display both the source and disassembled form of the assembly code.
14
14
15
-
Note that putting multiple assembly instructions or source language statements on one line can hamper debugging. In source mode, you can use the debugger to set breakpoints on a single line but not on individual statements on the same line. The same principle applies to an `__asm` block defined as a C macro, which expands to a single logical line.
15
+
Note that putting multiple assembly instructions or source language statements on one line can hamper debugging. In source mode, you can use the debugger to set breakpoints on a single line but not on individual statements on the same line. The same principle applies to an **`__asm`** block defined as a C macro, which expands to a single logical line.
16
16
17
17
If you create a mixed source and assembly listing with the [/FAs](../../build/reference/fa-fa-listing-file.md) compiler option, the listing contains both the source and assembly forms of each assembly-language line. Macros are not expanded in listings, but they are expanded during compilation.
C macros offer a convenient way to insert assembly code into your source code, but they demand extra care because a macro expands into a single logical line. To create trouble-free macros, follow these rules:
12
12
13
-
- Enclose the `__asm` block in braces.
13
+
- Enclose the **`__asm`** block in braces.
14
14
15
-
- Put the `__asm` keyword in front of each assembly instruction.
15
+
- Put the **`__asm`** keyword in front of each assembly instruction.
16
16
17
17
- Use old-style C comments ( `/* comment */`) instead of assembly-style comments ( `; comment`) or single-line C comments ( `// comment`).
18
18
@@ -28,21 +28,21 @@ To illustrate, the following example defines a simple macro:
28
28
}
29
29
```
30
30
31
-
At first glance, the last three `__asm` keywords seem superfluous. They are needed, however, because the macro expands into a single line:
31
+
At first glance, the last three **`__asm`** keywords seem superfluous. They are needed, however, because the macro expands into a single line:
32
32
33
33
```cpp
34
34
__asm /* Port output */ { __asm mov al, 2 __asm mov dx, 0xD007 __asm out dx, al }
35
35
```
36
36
37
-
The third and fourth `__asm` keywords are needed as statement separators. The only statement separators recognized in `__asm` blocks are the newline character and `__asm` keyword. Because a block defined as a macro is one logical line, you must separate each instruction with `__asm`.
37
+
The third and fourth **`__asm`** keywords are needed as statement separators. The only statement separators recognized in **`__asm`** blocks are the newline character and **`__asm`** keyword. Because a block defined as a macro is one logical line, you must separate each instruction with **`__asm`**.
38
38
39
-
The braces are essential as well. If you omit them, the compiler can be confused by C or C++ statements on the same line to the right of the macro invocation. Without the closing brace, the compiler cannot tell where assembly code stops, and it sees C or C++ statements after the `__asm` block as assembly instructions.
39
+
The braces are essential as well. If you omit them, the compiler can be confused by C or C++ statements on the same line to the right of the macro invocation. Without the closing brace, the compiler cannot tell where assembly code stops, and it sees C or C++ statements after the **`__asm`** block as assembly instructions.
40
40
41
-
Assembly-style comments that start with a semicolon (**;**) continue to the end of the line. This causes problems in macros because the compiler ignores everything after the comment, all the way to the end of the logical line. The same is true of single-line C or C++ comments ( `// comment`). To prevent errors, use old-style C comments ( `/* comment */`) in `__asm` blocks defined as macros.
41
+
Assembly-style comments that start with a semicolon (**;**) continue to the end of the line. This causes problems in macros because the compiler ignores everything after the comment, all the way to the end of the logical line. The same is true of single-line C or C++ comments ( `// comment`). To prevent errors, use old-style C comments ( `/* comment */`) in **`__asm`** blocks defined as macros.
42
42
43
-
An `__asm` block written as a C macro can take arguments. Unlike an ordinary C macro, however, an `__asm` macro cannot return a value. So you cannot use such macros in C or C++ expressions.
43
+
An **`__asm`** block written as a C macro can take arguments. Unlike an ordinary C macro, however, an **`__asm`** macro cannot return a value. So you cannot use such macros in C or C++ expressions.
44
44
45
-
Be careful not to invoke macros of this type indiscriminately. For instance, invoking an assembly-language macro in a function declared with the `__fastcall` convention may cause unexpected results. (See [Using and Preserving Registers in Inline Assembly](../../assembler/inline/using-and-preserving-registers-in-inline-assembly.md).)
45
+
Be careful not to invoke macros of this type indiscriminately. For instance, invoking an assembly-language macro in a function declared with the **`__fastcall`** convention may cause unexpected results. (See [Using and Preserving Registers in Inline Assembly](../../assembler/inline/using-and-preserving-registers-in-inline-assembly.md).)
Copy file name to clipboardExpand all lines: docs/assembler/inline/inline-assembler-overview.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,9 @@ The inline assembler lets you embed assembly-language instructions in your C and
12
12
13
13
Because the inline assembler doesn't require separate assembly and link steps, it is more convenient than a separate assembler. Inline assembly code can use any C or C++ variable or function name that is in scope, so it is easy to integrate it with your program's C and C++ code. And because the assembly code can be mixed with C and C++ statements, it can do tasks that are cumbersome or impossible in C or C++ alone.
14
14
15
-
The [__asm](../../assembler/inline/asm.md) keyword invokes the inline assembler and can appear wherever a C or C++ statement is legal. It cannot appear by itself. It must be followed by an assembly instruction, a group of instructions enclosed in braces, or, at the very least, an empty pair of braces. The term "`__asm` block" here refers to any instruction or group of instructions, whether or not in braces.
15
+
The [__asm](../../assembler/inline/asm.md) keyword invokes the inline assembler and can appear wherever a C or C++ statement is legal. It cannot appear by itself. It must be followed by an assembly instruction, a group of instructions enclosed in braces, or, at the very least, an empty pair of braces. The term "**`__asm`** block" here refers to any instruction or group of instructions, whether or not in braces.
16
16
17
-
The following code is a simple `__asm` block enclosed in braces. (The code is a custom function prolog sequence.)
17
+
The following code is a simple **`__asm`** block enclosed in braces. (The code is a custom function prolog sequence.)
18
18
19
19
```cpp
20
20
// asm_overview.cpp
@@ -36,15 +36,15 @@ void __declspec(naked) main()
36
36
}
37
37
```
38
38
39
-
Alternatively, you can put `__asm` in front of each assembly instruction:
39
+
Alternatively, you can put **`__asm`** in front of each assembly instruction:
40
40
41
41
```cpp
42
42
__asm push ebp
43
43
__asm mov ebp, esp
44
44
__asm sub esp, __LOCAL_SIZE
45
45
```
46
46
47
-
Since the `__asm` keyword is a statement separator, you can also put assembly instructions on the same line:
47
+
Since the **`__asm`** keyword is a statement separator, you can also put assembly instructions on the same line:
0 commit comments