The HLA high-level language control structures have a few drawbacks: (1) they're not true assembly language instructions, (2) complex boolean expressions support only short-circuit evaluation, and (3) they often introduce inefficient coding practices into a language that most people use only 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 (that is, those that involve a boolean expression). For example, a hybrid if
statement takes the following form:
if( #{instructions
}# ) thenstatements
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; repeatstatements
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 pseudo-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 ); jnb false; }# ) then inc( eax ); endif;
The jnb
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 ); jnb 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 ); jnae false; cmp( eax, k ); jnae 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 ); jnb false; }# ) then mov( ebx, eax ); endif;
Because 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 should notice is that using hybrid statements eliminates the need to insert labels throughout your code. This can make 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, whereas 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, whereas 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.