5.22 The INCLUDE Directive


5.22 The #INCLUDE Directive

The #include directive, when encountered in a source file, switches program input from the current file to the file specified in the parameter list of the include directive. This allows you to construct text files containing common constants, types, source code, and other HLA items, and include such files into the assembly of several separate programs. The syntax for the #include directive is

      #include( "filename" ) 

Filename must be a valid filename. HLA merges the specified file into the compilation at the point of the #include directive. Note that you can nest #include statements inside files you include. That is, a file being included into another file during assembly may itself include a third file. In fact, the stdlib.hhf header file you see in most example programs is really nothing more than a bunch of includes (see Listing 5-18).

Listing 5-18: The stdlib.hhf Header File, as of 01/01/2000.

start example
 #include( "hla.hhf" ) #include( "x86.hhf" ) #include( "misctypes.hhf" ) #include( "hll.hhf" ) #include( "excepts.hhf" ) #include( "memory.hhf" ) #include( "args.hhf" ) #include( "conv.hhf" ) #include( "strings.hhf" ) #include( "cset.hhf" ) #include( "patterns.hhf" ) #include( "tables.hhf" ) #include( "arrays.hhf" ) #include( "chars.hhf" ) #include( "math.hhf" ) #include( "rand.hhf" ) #include( "stdio.hhf" ) #include( "stdin.hhf" ) #include( "stdout.hhf" ) 
end example

By including stdlib.hhf in your source code, you automatically include all the HLA library modules. It's often more efficient (in terms of compile time and size of code generated) to provide only those #include statements for the modules you actually need in your program. However, including stdlib.hhf is extremely convenient and takes up less space in this text, which is why most programs appearing in this text use stdlib.hhf.

Note that the #include directive does not need to end with a semicolon. If you put a semicolon after the #include, that semicolon becomes part of the source file and is the first character following the included source during compilation. HLA generally allows spare semicolons in various parts of the program, so you will often see a #include statement ending with a semicolon. In general, though, you should not get in the habit of putting semicolons after #include statements because there is the slight possibility this could create a syntax error in certain circumstances.

Using the #include directive by itself does not provide separate compilation. You could use the #include directive to break up a large source file into separate modules and join these modules together when you compile your file. The following example would include the printf.hla and putc.hla files during the compilation of your program:

      #include( "printf.hla" )      #include( "putc.hla" ) 

Now your program will benefit from the modularity gained by this approach. Alas, you will not save any development time. The #include directive inserts the source file at the point of the #include during compilation, exactly as though you had typed that code yourself. HLA still has to compile the code and that takes time. Were you to include all the files for the Standard Library routines in this manner, your compilations would take forever.

In general, you should not use the #include directive to include source code as shown above.[26] Instead, you should use the #include directive to insert a common set of constants, types, external procedure declarations, and other such items into a program. Typically an assembly language include file does not contain any machine code (outside of a macro; see the chapter on macros for details). The purpose of using #include files in this manner will become clearer after you see how the external declarations work.

[26]There is nothing wrong with this, other than the fact that it does not take advantage of separate compilation.




The Art of Assembly Language
The Art of Assembly Language
ISBN: 1593272073
EAN: 2147483647
Year: 2005
Pages: 246
Authors: Randall Hyde

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