To start with we'll write a small program and run it on the instruction set simulator. This will give you a general idea of how things work. Later we will describe how to run a program on the real target computer.
The subject of this chapter is a small program called "hello". Using library functions and simulated input-output to do the printing, it simply prints the message "Hello World" on the terminal. You will find the source code in the directory /examples on the M1750 Ada CD-ROM.
Three steps are needed to create an executable file from Ada source files:
The source file(s) must first be compiled.
The file(s) then must be bound using the M1750 Ada binder.
All appropriate object files must be linked to produce an executable file.
Any editor may be used to prepare an Ada program. If emacs is used, the optional Ada mode may be helpful in laying out the program. The program text is a normal text file. We will suppose in our initial example that you have used your editor to prepare the following text file:
Example 1-1. The Source File
with Text_IO; procedure Hello is begin Text_IO.Put_Line ("Hello World"); end Hello;
The Ada compiler requires that each file contains a single compilation unit whose file name corresponds to the unit name with periods replaced by hyphens and whose extension is .ads for a spec and .adb for a body. This example file should be named hello.adb.
You can compile the file using the following command:
The command m1750-coff-gcc is used to run the compiler. This command will accept programs in several languages including Ada 95, C, assembly language and object code. It determines you have given it an Ada program by the filename extension (.ads or .adb), and will call the Ada compiler to compile the specified file.
The -c switch is always required. It tells gcc to stop after compilation. (For C programs, gcc can also do linking, but this capability is not used directly for Ada programs, so the -c switch must always be present.)
This compile command generates the file hello.o which is the object file corresponding to the source file hello.adb. It also generates a file hello.ali, which contains additional information used to check that an Ada program is consistent. To get an executable file, we then use gnatbind to bind the program and gnatlink to link the program.
The result is an executable file called hello.
You may use the option -v to get more information about which version of the tool was used and which files were read.
A simpler method of carrying out these steps is to use the gnatmake command. gnatmake is a master program that invokes all of the required compilation, binding and linking tools in the correct order. In particular, it automatically recompiles any modified sources, or sources that depend on modified sources, so that a consistent compilation is ensured.
The following example shows how to use gnatmake to build the program hello.
Example 1-4. Using gnatmake to Compile
$ m1750-coff-gnatmake hello m1750-coff-gcc -c hello.adb m1750-coff-gnatbind -x hello.ali m1750-coff-gnatlink hello.ali
Again, the result is an executable file called hello.