Chapter 4: Optimizing C Logical Structures with Assembly Language

image from book  Download CD Content

Overview

Programmers who write in high-level languages use assembly blocks and separately compiled modules to decrease the sizes and improve the performance of their applications. In this section, we will look at how the most frequently used constructions of high-level programming languages are implemented in the assembler. Constructions such as if else , do while , etc. carry certain redundancy. Therefore, by using their assembly analogs, you will be able to increase the performance of your applications. It should be mentioned that all high-level languages usually have inline assemblers, but we will postpone a discussion of the C++ .NET inline assembler until Part 3 .

Analysis of programs written in high-level programming languages reveals their weak points, especially the unpractical use of selection instructions and loop computations . Processing large arrays and strings and mathematical calculations significantly decreases performance of programs. These is no high-level languages compiler that could completely remove redundancy and non-optimality from the code, no matter how hard it would try to optimize the size and performance of an executable module. This is also true for Intel compiler, which, we believe, has good optimization characteristics at the processor command level.

Loop computation and constructions such as if else , while , do while , and switch case can be optimized most easily. As a rule, optimization of selection instructions and loops is based on using comparison commands and conditional jumps depending on the result of comparison. Generally, this can be presented as follows :

 ...    cmp     operand1, operand2    Jcond   label1    <commands 1>    jmp     label2  label1:    <commands 2>  label2:     ... 

Here, operand1 and operand2 are variables and/or expressions, and Jcond is a conditional jump command (such as je , jl , jge , jz , or other).

Any high-level language construction, no matter how complicated it might be, can be represented as a combination of conditional jumps and comparison commands. In this chapter, we will look at variants of implementation of high-level language constructions for practical purposes. We will begin with the if statement.



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