We will consider the possible ways of optimizing the programs by using assembly language.
The first approach is to include a separate assembly module into a C++ program code. This assembly module may include a function or a group of functions that perform some calculations. You can develop such modules separately from the main program, and compile them by using a stand-alone assembler compiler such as Microsoft Macro Assembler (MASM) or Borland Turbo Assembler (TASM). The result is an object module file that has the OBJ extension. You can include it into the project of a C++ application (in the Visual Studio .NET environment) and use the functions of this module according to the calling conventions. As compared to other options, this offers you certain advantages:
Once developed, the object module can be used in different applications.
There is no need to develop specific function interface (as is the case with DLL libraries) to call these functions from within other programs.
It is easier to debug an assembly module separately, using its own development environment.
Note that the separate assembly modules may also contain several interrelated functions making up a larger calculation block.
The second approach to combining assembly language with high-level languages is based on the use of the built-in assembler. Using the built-in assembly language for developing procedures is convenient , primarily due to fast debugging. As a procedure is developed in the body of the main program, you do not need any specialized tools to integrate this procedure with the program that calls it. Neither do you have to concern yourself with the order of sending the parameters into the procedure you call, or with restoring the stack. To implement the functions in the built-in assembly language, you do not need to write the prologue and the epilogue , as it is needed in case of developing the assembly modules separately.
One disadvantage of this optimization approach pertains to certain limitations of the operation of the assembly modules, imposed by the development environment. Also note that the procedures developed in the built-in assembly language cannot be transformed into external modules for reuse.