(This is the older material - click here - for current specification content)

7. Features of a compiler (4)

Code optimisation

A compiler translates source code into machine or object code.

But a collection of high level statements can be translated into machine code in many different ways. Like this:


For x = 1 to 10

p = p + 1

Next x

How many ways are there to create machine code that will carry out these instructions? Answer: Many!

This is what makes compilers different from one another. And this is one of the features that makes one compiler better than another one.

For example, you could have two compilers, each one translating 'C' language high level source code into Intel x86 machine code. But a poor compiler will produce clunky, inefficient, bloated machine code whilst the better one produces efficient, tightly-coded, fast machine code that takes advantage of all the special features of the target CPU and makes minimum use of memory.

Making software run faster or in less memory is called 'code optimisation'. And a good compiler will have many code optimisation tricks up its sleeve (all kept secret of course by the compiler manufacturer!).


Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: modern compilers

Interesting fact:

In the most critical part of a program, i.e. one that needs to run as fast or as efficiently as possible, programmers will sometimes invest the time and effort to produce hand-coded assembly/ machine code and by-pass the skills of the compiler author. This is often the case in the most critical part of real-time control software, where in-time performance is vital. Then they leave the less time-critical part of the software to the compiler.



Copyright © www.teach-ict.com