_ ASM
Microsoft details:
The _ ASM keyword starts inline assembly and can be written in any valid C/C ++ statement. it cannot appear separately. it must be followed by assembly instructions, a set of instructions contained in braces, or a pair of empty parentheses. the term "_ ASM block" is either an instruction or a group of instructions, whether or not they are in brackets.
BelowCodeThe clip is a simple _ ASM block in parentheses.
_ ASM
{
MoV Al, 2
MoV dx, 0xd007
Out Al, DX
}
Another way is to place _ ASM before each Assembly command.
_ ASM mov Al, 2
_ ASM mov dx, 0xd007
_ ASM out Al, DX
Because the _ ASM keyword is a statement separator, you can also put the Assembly command in the same line:
_ ASM mov Al, 2 _ ASM mov dx, 0xd007 _ ASM out Al, DX
The above three examples generate the same code, but the first style (enclose the _ ASM block in parentheses) has some advantages. Parentheses can clearly separate C or C ++ code from assembly code, and avoid unnecessary repeated _ ASM keywords. Parentheses can also avoid ambiguity. If you want to place a C or C ++ statement in the same row of the _ ASM block, you must enclose the block in parentheses.
. Without parentheses, the compiler cannot tell where the Assembly Code stops and where the C or C ++ code starts. Finally, because the text in the brackets is in the same format as the original MASM, you can easily cut and paste the text from an existing MASM source file to the file.
Unlike the brackets in C and C ++, the brackets in the _ ASM block have no effect on the variable scope. You can also nest the _ ASM block, which has no effect on the variable scope.