1.4 Some Basic HLA Data Declarations


1.4 Some Basic HLA Data Declarations

HLA provides a wide variety of constant, type, and data declaration statements. Later chapters will cover the declaration section in more detail, but it's important to know how to declare a few simple variables in an HLA program.

HLA predefines several different signed integer types including int8, int16, and int32, corresponding to 8-bit (one byte) signed integers, 16-bit (two byte) signed integers, and 32-bit (four byte) signed integers, respectively.[3] Typical variable declarations occur in the HLA static variable section. A typical set of variable declarations takes the form shown in Figure 1-2.

click to expand
Figure 1-2: Static Variable Declarations.

Those who are familiar with the Pascal language should be comfortable with this declaration syntax. This example demonstrates how to declare three separate integers, i8, i16, and i32. Of course, in a real program you should use variable names that are a little more descriptive. While names like "i8" and "i32" describe the type of the object, they do not describe its purpose. Variable names should describe the purpose of the object.

In the static declaration section, you can also give a variable an initial value that the operating system will assign to the variable when it loads the program into memory. Figure 1-3 provides the syntax for this.

click to expand
Figure 1-3: Static Variable Initialization.

It is important to realize that the expression following the assignment operator (":=") must be a constant expression. You cannot assign the values of other variables within a static variable declaration.

Those familiar with other high level languages (especially Pascal) should note that you may only declare one variable per statement. That is, HLA does not allow a comma-delimited list of variable names followed by a colon and a type identifier. Each variable declaration consists of a single identifier, a colon, a type ID, and a semicolon.

Listing 1-2 provides a simple HLA program that demonstrates the use of variables within an HLA program.

Listing 1-2: Variable Declaration and Use.

start example
 Program DemoVars; #include( "stdlib.hhf" ) static    InitDemo:       int32 := 5;    NotInitialized: int32; begin DemoVars;    // Display the value of the pre-initialized variable:    stdout.put( "InitDemo's value is ", InitDemo, nl );    // Input an integer value from the user and display that value:    stdout.put( "Enter an integer value: " );    stdin.get( NotInitialized );    stdout.put( "You entered: ", NotInitialized, nl ); end DemoVars; 
end example

In addition to static variable declarations, this example introduces three new concepts. First, the stdout.put statement allows multiple parameters. If you specify an integer value, stdout.put will convert that value to its string representation on output. The second new feature Listing 1-2 introduces is the stdin.get statement. This statement reads a value from the standard input device (usually the keyboard), converts the value to an integer, and stores the integer value into the NotInitialized variable. Finally, this program also introduces the syntax for (one form of) HLA comments. The HLA compiler ignores all text from the "//" sequence to the end of the current line. Those familiar with Java, C++, and Delphi/Kylix should recognize these comments.

[3]A discussion of bits and bytes will appear in the next chapter if you are unfamiliar with these terms.




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