Control structures in High Level Programming Languages
 

Control structures alters the default program flow

Commonly used control structures in high level programming languages:

  • The if-statement
  • The if-else-statement
  • The switch-statement

  • The while-statement
  • The for-statement
  • The do-while-statement

 

I will omit the switch-statement because it's equivalent to nested if-else-statements

I will omit the do-while-statement because it is rarely used in programs

Assembler instructions used to implement control structures in assembler

Control structure in high level languages are implemented in Assembler using 2 assembler instructions:

  1. A compare instruction that:

      • compares 2 values      and

      • set the status flags (N, Z, V, C) in the PSR (Processor Status Register) according to result of the comparison

  2. Conditional and unconditional branch instructions:

      • is a group of (related) instructions

      • can make the CPU "jump" to a given memory location


      • Jumps can be conditional or unconditional (= always)

      • Jumps will result in out-of-order program flow

Order of discussion
 

Topics discussed in next few slides/webpages:

  1. The mechanism used in the CPU to change the program flow

    (You have seen the mechanism before. This time, I will illustrate the mechanism with assembler code)

  2. How to use this mechanism to construct the program flow that reflects the execution of if/if-else statements

  3. How to use this mechanism to construct the program flow that reflects the execution of while/for statements