The following code fragment is a simple __asm block enclosed in braces:
__asm {
mov al, 2
mov dx, 0xD007
out dx, al
}
Alternatively, you can put __asm in front of each assembly instruction:
__asm mov al, 2
__asm mov dx, 0xD007
__asm out dx, al
Because the __asm keyword is a statement separator, you can also put assembly instructions on the same line:
__asm mov al, 2 __asm mov dx, 0xD007 __asm out dx, al
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.
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.
END Microsoft Specific