THE MECHANICS OF CREATING AN EXECUTABLE COMPUTER PROGRAM


1. SOURCE CODE

Using a high level language, such as Ada, a program can be written as ordinary text stored in a file. This text is referred to as the source code. A file containing text is usually referred to as a text file. Text files are created using a program called a text editor. This is a program the same as any other, input is usually from the keyboard and the output is a text file. Text editors allow users to create and edit text files. There are many examples of such programs, the more sophisticated are referred to as word processors and are designed to produce documents rather than programs. Text editors can be viewed as simple word processing programs. The Unix system we will be using supports a number of editors, we will be using "ved" (the HP-UX visual editor) .


2. OBJECT MODULE

Once a program exists as a text file the next stage is to translate this text into machine code so that the program can be executed. This is achieved using a translation program called a compiler. Different compilers exist for each different high level programming language. Thus to compile an Ada program we will need an Ada compiler. Computer systems often include a number of different compilers on delivery. When "invoked" a compiler reads source code and checks that the program is syntactically correct, i.e. that it obeys the rules of the chosen high level language. Note that all programming languages have special rules regarding the form of different program constructions - we say that each language has its own syntax. If the compiler finds syntactic errors an error message will appear on the screen in which case the programmer must re-invoke the text editor, correct the program and then attempt to compile it again. This process normally proceeds for a number of iterations. If no errors are found the compiler goes on to translate the text into machine code. The code produced in this manner is referred to as the object module and it is saved in a file in secondary storage. Note that, because different models of computer have different machine codes, a compiler designed for one computer will not work on another. Different compilers are needed for different machines. However, the text file can easily be taken from one model of computer to another. We say that the program is portable. Portability is an important issue in software development and an often quoted advantage of high level languages.


3. LINKING

The next stage is to "link" in library routines that will be required by the program. These routines are pieces of program code supplied with the language which can be incorporated into programs. The aim is to speed up the programming process by allowing programmers to use existing blocks of code that perform often required operations, for example to facilitate input from the keyboard or output to the computer screen. Library routines are stored in files the same way that all other data is stored. The term library is used in the sense that programmers a free to select routines in a manner analogous to the way that books can be chosen from traditional libraries. There is nothing to stop programmers from writing their own library routines, indeed it is often desirable to do so, but more on this later

Linking is achieved using another special program called a linker. This gathers together the constituent parts of a program (object module and library routines) and produces a single (executable) machine code file called the load module which is saved in secondary storage.

For large applications the desired end program might comprise several program text files (each possibly produced by a different programmer) and consequently several object modules. In this case the linker can also be used to incorporate these separate compilations into a single load module.


4. SUMMARY

To summarise the above, the stages in the making of a working program are as follows:

  1. Create the program text (source code) using a text editor.
  2. Compile the source code to create an object module using a compiler.
  3. Link in library routines (and possibly other object modules) using a linker to produce the final load module.
DATA FLOW DURING COMPILATION

The load module may now be run (executed) through a command to the operating system as described previously. The command to execute a program comprises the name of the file in which the program is stored. The command causes the operating system to search for the required file in secondary memory and (if found) copy it into primary memory where it is then executed under the control of the CU. On completion control is returned to the operating system. The "spent" copy of the program remains in primary memory until the cells used are eventually overwritten by the execution of another program.


4.1. The ICC Compiler

We will be using an Ada compiler called the ICC compiler. This simplifies the process of creating an executable program by combining the object module and linking stages. Thus to compile a program using the ICC compiler we simply issue the following single command:

$ ICC fileName.ada


5. USE OF INTERPRETERS

The alternative manner in which a program written in a high level language may be "run" is through the use of an interpreter (instead of a compiler). Using an interpreter the source code (program text) is created in exactly the same manner as described above. The interpreter is then run with the program text in secondary storage as input data. Just like the compiler the interpreter reads the text and checks that the program has no syntax errors. The difference is that the interpreter never translates the program to machine code. Instead it "interprets" the program step by step and carries out the tasks of the program. From the user's point of view, it appears as if the program is being executed. The advantage is that interpreters provide a faster and easier way of testing small programs or fragments of programs. The disadvantage is that programs run much more slowly.




Created and maintained by Frans Coenen. Last updated 11 October 1999