TOC PREV NEXT INDEX

Webster Home Page



2.13 Hybrid Control Structures in HLA

The HLA high level language control structures have a few drawbacks: (1) they're not true assembly language instructions, (2) complex boolean expressions only support short circuit evaluation, and (3) they often introduce inefficient coding practices into a language that most people only use when they need to write high-performance code. On the other hand, while the 80x86 low level control structures let you write efficient code, the resulting code is very difficult to read and maintain. HLA provides a set of hybrid control structures that allow you to use pure assembly language statements to evaluate boolean expressions while using the high level control structures to delineate the statements controlled by the boolean expressions. The result is code that is much more readable than pure assembly language without being a whole lot less efficient.

HLA provides hybrid forms of the IF..ELSEIF..ELSE..ENDIF, WHILE..ENDWHILE, REPEAT..UNTIL, BREAKIF, EXITIF, and CONTINUEIF statements (i.e., those that involve a boolean expression). For example, a hybrid IF statement takes the following form:

	if( #{  <<statements>> }# ) then <<statements>> endif;
 

 

Note the use of #{ and }# operators to surround a sequence of instructions within this statement. This is what differentiates the hybrid control structures from the standard high level language control structures. The remaining hybrid control structures take the following forms:

while( #{ <<statements>> }# )  <<statements>> endwhile;
 
repeat <<statements>> until( #{ <<statements>> }# );
 
breakif( #{ <<statements>> }# );
 
exitif( #{ <<statements>> }# );
 
continueif( #{ <<statements>> }# );
 

 

The statements within the curly braces replace the normal boolean expression in an HLA high level control structure. These particular statements are special insofar as HLA defines two labels, true and false, within their context. HLA associates the label true with the code that would normally execute if a boolean expression were present and that expression's result was true. Similarly, HLA associates the label false with the code that would execute if a boolean expression in one of these statements evaluated false. As a simple example, consider the following two (equivalent) IF statements:

if( eax < ebx ) then inc( eax ); endif;
 

 
if
 
( #{
 
	cmp( eax, ebx );
 
	jnl false;
 
}# ) then
 
	inc( eax );
 

 
endif;
 

 

The JNL that transfers control to the false label in this latter example will skip over the INC instruction if EAX is not less than EBX. Note that if EAX is less than EBX then control falls through to the INC instruction. This is roughly equivalent to the following pure assembly code:

cmp( eax, ebx );
 
jnl falseLabel;
 
	inc( eax );
 
falseLabel:
 

 

As a slightly more complex example, consider the statement

if( eax >= J && eax <= K ) then sub( J, eax ); endif;
 

 

The following hybrid IF statement accomplishes the above:

if
 
( #{
 
	cmp( eax, J );
 
	jnge false;
 
	cmp( eax, K );
 
	jnle false;
 
}# ) then
 
	sub( J, eax );
 

 
endif;
 

 

As one final example of the hybrid IF statement, consider the following:

// if( ((eax > ebx) && (eax < ecx)) || (eax = edx)) then mov( ebx, eax ); endif;
 

 
if
 
( #{
 
	cmp( eax, edx );
 
	je true;
 
	cmp( eax, ebx );
 
	jng false;
 
	cmp( eax, ecx );
 
	jnl false;
 
}# ) then
 
	mov( ebx, eax );
 

 
endif;
 

 

Since these examples are rather trivial, they don't really demonstrate how much more readable the code can be when using hybrid statements rather than pure assembly code. However, one thing you notice is that the use of hybrid statements eliminate the need to insert labels throughout your code. This is what makes your programs easier to read and understand.

For the IF statement, the true label corresponds to the THEN clause of the statement; the false label corresponds to the ELSEIF, ELSE, or ENDIF clause (whichever follows the THEN clause). For the WHILE loop, the true label corresponds to the body of the loop while the false label is attached to the first statement following the corresponding ENDWHILE. For the REPEAT..UNTIL statement, the true label is attached to the code following the UNTIL clause while the false label is attached to the first statement of the body of the loop. The BREAKIF, EXITIF, and CONTINUEIF statements associate the false label with the statement immediately following one of these statements, they associate the true label with the code normally associated with a BREAK, EXIT, or CONTINUE statement.

2.14 Putting It All Together

In this chapter we've taken a look at the low-level, or "pure" assembly language, implementation of several common control structures. Although HLA's high level control structures are easy to use and quite a bit more readable than their low-level equivalents, sometimes efficiency demands a low-level implementation. This chapter presents the blueprints for such transformations.

While this chapter covers the principle high level control structures and their translation to assembly language, there are some additional control structures that this chapter does not consider. Iterators and the TRY..ENDTRY statement are two good examples. Fear not, however, the volume on Advanced Assembly Language Programming will tidy up those loose ends.


Web Site Hits Since
Jan 1, 2000

TOC PREV NEXT INDEX