How to Use ASM in Visual C
The Visual C++ programming language is Microsoft's .Net adaptation of C/C++. With Visual C++, you can write C/C++ code that interfaces with the .Net framework to take advantage of its rich suite of tools. You can also use Visual C++ to invoke assembly code instructions in line with your program. This is a powerful way to optimize certain procedures for specific hardware. In Visual C++, inline assembly instructions are accessed using the __ASM keyword, followed by assembly instructions.
Instructions
-
-
1
Open Microsoft Visual Studio 2010 by clicking on its icon in the Start menu, located within the "Microsoft Visual Studio 2010" directory.
-
2
Select "File," "New" and "Project" from the list of menu items at the top of the Visual Studio 2010 window. A "New Project" window appears.
-
-
3
Select "Other Language," "Visual C++," "General" and press the "Empty Project" button. A new project is created.
-
4
Select "File," "New" and "File" from the list of menu items at the top of the window.
-
5
Select "Visual C++" and press the "C++ File" button. An empty source code file appears in the text editor window.
-
6
Create a main function by writing the following line of code:
int main() {}
-
7
Add an inline assembly statement to the source code. To do this, you can write the following line in between the curly brackets of the main function (the assembly code here is for demonstrative purposes and doesn't accomplish anything):
__asm push bx
__asm push cx
__asm push dx
-
8
Write the previous assembly instruction using the alternative syntax of __ASM, like this:
__asm {
push bx
push cx
push dx
}
-
1