Preface

The evolution of software development tools during the past few decades is astonishing for anyone involved in software development. This is especially true in creating applications for the Windows operating system family. Modern tools make it possible to create an application with a few mouse clicks, and this often allows a programmer to save weeks or even months of tedious work. In fact, each development environment contains application wizards that can create an application with particular features.

As one of the most powerful development tools, the Microsoft Visual C++ .NET development environment offers the programmer a wide variety of features for the development of applications of any type and level of complexity. Nevertheless, most serious applications are written with much manual work. This is because none of the high-level language development tools can provide maximum performance. This is the truth based on the structure and semantics of high-level languages.

A possible solution to the application optimization problem is the use of assembly language. Note that it is possible to write an application without using this language. There are many programs that do not require optimization. However, with regard to real-time applications, device drivers, multimedia applications, sound processing applications, graphics applications, and any applications, for which the time of execution is important, the use of assembly language is inevitable because no other optimization method will work.

In essence, assembly language is the language of the processor, and it will disappear only when processors disappear! That is why assembly language has one basic advantage over high level languages (and it always will): It is the quickest. Most applications working in real time are either written in assembly language or use assembly modules in crucial parts of code.

Many programmers who write in high level languages are afraid of using the assembler in their work. Programmers sometimes complain that assembly language is too complicated and difficult to learn; however, this is not true. Assembly language is no more complicated than other programming languages, and both experienced programmers and novices can easily learn it.

Also, powerful tools for the development of applications in the assembler appeared recently. This allows us look at the development of applications in this language from another point of view. Among such development tools are MASM32 macro assembler, AsmStudio, and NASM. These and other tools combine the flexibility and speed of assembly language and an up-to-date graphic interface. Numerous function libraries created for assembly language made this languages properties close to those of high-level application development tools. Therefore, there are no concrete reasons for the contraposition of assembly language to high level languages on the basis of its complexity.

This book will focus on the use of assembly language in programs created with Visual C++ .NET 2003, currently the most powerful C++ development environment. The material of this book will disclose two relatively independent aspects of using it as a stand-alone tool for creating individual procedures in the form of object modules and as a built-in tool integrated in C++ .NET. Microsoft continually improves the inline assembler.

This book is not a tutorial on assembly language, nor on C++ .NET. It assumes that you have a certain knowledge of these programming areas.

To create applications in Windows successfully, you should know the basics of how applications run in this operating system. You do not have to know the Windows architecture in detail because all of the necessary information is given when discussing the code of examples.

This book is intended to be a practice aid for programmers who wish to know more about programming in assembly language. Programmers writing in Visual C++ .NET will find much useful information for their work.

The book includes many examples with subsequent dissection of their code, with the belief that every theoretical issue should be supported with an example of code. It is the most effective and fastest way to learn how to write programs. Some of the examples are unique programs that cannot be found anywhere else.

All the examples were tested and run correctly. Long and complicated programs are avoided here because it would be easy to overlook key issues when analyzing such programs. Each example is designed so that it is easy to modify for use in your projects.

Visual C++ .NET 2003 was chosen as a development tool.Regarding examples in assembly language, Microsoft MASM is used. It is recommended that you use MASM32, which includes Microsoft compiler and linker. The compiler is ML version 6.14, and the linker is LINK version 5.12.

All examples use a simplified syntax of assembly language and as few high-level constructions as possible. Only the information necessary for work is provided, rather than a comprehensive description of the MASM compiler. Readers who wish to gain a deeper knowledge of this compiler will find ample information in other sources.

The material is presented in a logical order and avoids both excessive code and unnecessary theorizing. It is difficult to look at all aspects of software optimization in Windows in one book. Nevertheless, I believe the material of this book will be useful for programmers.

The Structure of the Book

This book is intended as a practice aid on C++ .NET 2003 program optimization with assembly language. Two main aspects of using this language are considered . First, assembly language can be used as a stand-alone tool for the development of individual modules. Stand-alone compilers make it possible to create both completed applications and individual object modules and function libraries that are widely used when developing applications on C++ .NET.

Second, the C++ .NET 2003 development environment includes powerful tools for programming in the inline assembly language. This book will discuss pros and cons of using the stand-alone compiler and the inline assembler.

The book is designed so that it is possible to study the material both selectively (through individual chapters) and sequentially, starting from the first chapter. This is convenient , because different readers can choose the material, in which they are interested. Both novice and experienced users will find necessary information in this book.

The practical side of using assembly language is emphasized to increase the performance of applications. Numerous examples allow you to better understand the principles of application development and optimization, and necessary theoretical material is given in the context of the examples. The tools of the assembler and high level languages are described only to the extent necessary to understand the material. It is not necessary to provide comprehensive reference material on the compiler and linkers of the macro assembler and C++ .NET in this book, because this material is covered in numerous books and user manuals.

The examples of programs are designed so that they demonstrate key techniques of using assembly language. Generally, each example highlights one aspect of using assembly language. Therefore, the algorithms of such programs are simple, and the programs themselves are small. I did not write large applications and did not try to optimize as much as possible in one application intentionally. Each complicated application has its unique way to increase performance, and various combinations of particular methods are possible.

This book demonstrates how to use building blocks of optimization: assembly language of the MMX and SSE extensions, assembler analogs of C++ library functions, string primitive commands, and many others.

Practically all the examples are based on the C++ .NET 2003 sample console application. To develop object modules with assembly code, Microsoft MASM 6.14 macro assembler and C++ .NET 2003 inline assembly compiler are used.

The code of the examples is designed so that you can use it in your work. The examples provided are intended to be very practical for programmers.

The book consists of 15 chapters briefly described below.

  • Chapter 1 : Developing Efficient Program Code . This chapter discusses general issues of accelerating computational algorithms with assembly language. Program code is analyzed with consideration of the architecture of up-to-date processors. The basic principles of FPU, MMX, and SSE technologies are discussed.

  • Chapter 2 : Optimizing Calculation Algorithms . The material of this chapter is devoted to the most important aspects of assembly language from the point of view of increasing performance. Algorithms for processing mathematical expressions, data arrays, and strings are discussed. The capabilities of the mathematical coprocessor and the use of string-processing commands are demonstrated.

  • Chapter 3 : Developing and Using Procedures in Assembly Language . This chapter discusses development and optimization of subroutines in assembly language. Different methods of data processing and the use of registers and memory are discussed. In this context, the material of the chapter complements Chapter 2 . General issues of the interface of procedures written completely in assembly language to high-level languages are also discussed in this chapter. As in the previous chapter, numerous examples illustrate the material.

  • Chapter 4 : Optimizing C++ Logical Structures with Assembly Language . In this chapter, much attention is given to optimization of the most important constructions of C++ .NET: loops and conditional statements. Practical examples illustrate different methods for implementing these constructions in assembly language.

  • Chapter 5 : Assembly Module Interface to C++ Programs . This chapter looks at the use of separately compiled assembly modules in C++ programs. Building the interface of such modules to applications developed in C++ .NET 2003 is discussed. Calling standards and conventions are analyzed in detail; theoretical material is supported with examples.

  • Chapter 6 : Developing and Using Assembly Subroutines . While Chapter 5 looks at the main standards and conventions used when linking assembly modules with C++ .NET applications, this chapter gives further consideration to using parameters and choosing the methods of passing parameters to assembly functions.

  • Chapter 7 : Linking Assembly Modules with C++ .NET Programs . This chapter comprehensively discusses linking C++ .NET programs with stand-alone assembly modules. It considers issues that have almost never been discussed in literature such as linking applications with assembly modules.

  • Chapter 8 : Dynamic Link Libraries and Their Development in Assembly Language . Dynamic link libraries are one of the most important components of Windows. They contain many procedures and are a powerful tool for writing effective programs. The chapter discusses practical aspects of creating and using DLLs. Methods of creating DLLs in assembly language and C++ .NET are described.

  • Chapter 9 : Basic Structures of Visual C ++ .NET 2003 Inline Assembler . This chapter discusses the use of the C++ .NET inline assembly language to develop high-performance applications. The inline assembly language is a powerful tool for increasing application performance, and it has many advantages over stand-alone compilers. The program architecture of the C++ .NET inline assembler and its relation to C++ main structures are examined.

  • Chapter 10 : Inline Assembler and Application Optimization. MMX and SSE Tech nologies . Practical aspects of using the C++ .NET inline assembler are illustrated with examples of implementation of computational tasks . The issues of assembly extensions for the MMX and SSE technologies in the context of programming in C++ .NET have never been discussed in literature.

  • Chapter 11 : Optimizing Multimedia Applications with Assembly Language . This chapter looks at using assembly language in multimedia applications. It describes a few methods of optimization of multimedia applications using assembly language. Theoretical material is supported with practical examples.

  • Chapter 12 : Optimizing Multithread Applications with Assembly Language . The concept of multithreading in Windows is the basis for this family of operating systems. The use of threads allows a programmer to make an application simpler and use the advantages of parallel processing. Using assembly language in multithreaded applications can provide additional increase in performance. These issues are discussed in this chapter.

  • Chapter 13 : C++ Inline Assembler and Windows Time Functions . Most of applications that run in Windows use timers and time functions. Time functions are necessary when it comes to real-time operations, or when writing device drivers and multimedia applications. In this chapter, practical examples illustrate how to use the inline assembler to improve the performance of real-time applications.

  • Chapter 14 : Using Assembly Language for System Programming in Windows . This chapter looks at methods for optimization of system programming tasks in the Windows family of operating systems. The chapter demonstrates a few aspects of optimizing file operations, memory management, and inter-process communication.

  • Chapter 15 : Optimizing Procedure-Oriented Applications and System Services . This chapter discusses the principles of using the C++ .NET 2003 inline assembly language in procedure-oriented Windows applications and system services. The use of assembly language in each of these types of applications has peculiarities that are demonstrated in this chapter.

The material of this book is complemented with a reference on Intel processor command set. Since the complete command set includes hundreds of commands, only the most frequently used commands are listed. The CD-ROM accompanying this book will be also very useful. It contains all the examples given in the book.

I am very grateful to the staff at A-LIST Publishing for preparing this book for publication.

Special thanks to my wife Julie for invaluable help and support.



Visual C++ Optimization with Assembly Code
Visual C++ Optimization with Assembly Code
ISBN: 193176932X
EAN: 2147483647
Year: 2003
Pages: 50
Authors: Yury Magda

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net