AdvancedControlStructures - Advanced High Level Control...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Advanced High Level Control Structures Beta Draft - Do not distribute © 2001, By Randall Hyde Page 727 Ad vanced High Level Control Structures Chapter One 1.1 Chapter Overview V olume One introduced some basic HLA control structures lik e the IF and WHILE statements (see Some Basic HLA Control Structures ” on page 29 .). This section elaborates on some of those control struc - tures (discussing features that were a little too adv anced to present in V olume One) and it introduces the remaining high le v el language control structures that HLA pro vides. This includes a full discussion of HLA s boolean e xpressions, the TR Y ..ENDTR Y statement, the RAISE statement, the BEGIN..END/EXIT/EXITIF statements, and the SWITCH/CASE/ENDSWITCH statement the HLA Standard Library pro vides. 1.2 Conjunction, Disjunction, and Negation in Boolean Expressions One ob vious omission in HLA s high le v el control structures is the ability to use conjunction (logical AND), disjunction (logical OR), and ne g ation (logical NO T) in run-time boolean e xpressions. This omis - sion, ho we v er , has been in this te xt, not in the HLA language. HLA does pro vide these f acilities, this section will describe their use. HLA uses the “&&” operator to denote logical AND in a run-time boolean e xpression. This is a dyadic (tw o-operand) operator and the tw o operands must be le g al run-time boolean e xpressions. This operator e v aluates true if both operands e v aluate to true. Example: if( eax > 0 && ch = ‘a’ ) then mov( eax, ebx ); mov( ‘ ‘, ch ); endif; The tw o MOV statements above execute only if EAX is greater than zero and CH is equal to the character ‘a’. If either of these conditions is false, then program execution skips over the two MOV instructions. Note that the expressions on either side of the “&&” operator may be any expression that is legal in an IF statement, these expressions don’t have to be comparisons using one of the relational operators. For example, the following are all legal expressions: @z && al in 5..10 al in {‘a’..’z’} && ebx boolVar && !eax !fileio.eof( fileHandle ) && fileio.getc( fileHandle ) <> ‘ ‘ HLA uses short circuit e v aluation when compiling the “&&” operator . If the left-most operand e v alu - ates f alse, then the code that HLA generates does not bother e v aluating the second operand (since the whole e xpression must be f alse at that point). Therefore, in the last e xpression abo v e, the code will not e x ecute the call to fi leio.g etc if the fi le pointer is currently pointing at the end of the fi le. Note that an e xpression lik e “eax < 0 && ebx <> eax” is itself a le g al boolean e xpression and, therefore, may appear as the left or right operand of the “&&” operator . Therefore, e xpressions lik e the follo wing are perfectly le g al: eax < 0 && ebx <> eax && !ecx The “&&” operator is left associati ve, so the code that HLA generates evaluates the expression above in a left-to-right fashion. Note that if EAX is less than zero, the code will not test either of the remaining expres-
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Chapter One Volume Four Page 728
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern