Assembly Language Operations

Basic Branching

In a simple program, one instruction follows another and execution is a sequential process. The processor starts at the first instruction and works its way to the last instruction.

Frequently it will be essential for the processor to execute instructions in a different order. This might be to perform an iterative process such as a loop where the program executes a series of instruction and then returns to the start of the sequence to repeat the same set of instructions with different values. Alternatively the processor may have to make a decision, perhaps by performing a comparison operation, and on the basis of that comparison, skip over many instructions to reach a different section of the program and continue execution from the start of the new section.

This movement around a program is called branching. It is accomplished by suitable branch instructions, sometimes known as jump instructions.

The simplest branch instruction is:

  B label ; unconditionally branch to the instruction at "label"
  ...    
  ...    
label ...    

The B instruction is an unconditional branch - when the processor encounters such a branch, it always jumps to the designated point. In assembly language, it is possible and desirable to represent the destination of the branch by a symbolic label. The assembler translates this label into the correct memory location, saving the programmer from having to figure out where this actually will be!