Review: normal program flow and out-ot-order program flow
 

  • The in-order or normal program flow is when:

      • After executing the current instruction in the program:

        • the CPU fetches and executes the instruction that physically follows the current instruction in the program

  • An out-of-order program flow is when:

      • After executing an instruction in the program:

        • the CPU fetches and executes a instruction that is not the physically next instruction in the program

The branch assembler instruction
 

  • The (uncondional) branch instruction changes the program flow

  • Syntax of the branch assembler instruction:

           b     label              
        or
           bal   label   
      

    Effect:

      • The b label instruction will cause the CPU to:

        • "branch" or "jump" to the instruction marked by label

        I.e.:

        • After executing the "b label" instruction, the CPU will execute the instruction at the memory location marked label

DEMO program to show the effect of the branch instruction
 

DEMO:   /home/cs255001/demo/asm/6-if/branch.s

        .text
main:
        mov     r1, #1111    // Instructions executed in sequence
        mov     r2, #1111    // "normal" program flow
        mov     r3, #1111

        b       there        // Branch to location at label "there"

        mov     r4, #2222    // These instructions are SKIPPED over !
        mov     r5, #2222
        mov     r6, #2222

there:
        mov     r4, #4444    // <--- Next instruction after  b there
        mov     r5, #4444
        mov     r6, #4444
   

Note:   watch the values in the PC at each instruction !!!
            Normal program flow: PC increases +4