next up previous
Next: Programming IFs Up: SAL & SPIM Previous: MIPS Memory Layout

Branch Instructions

Branch instructions are used to implement IF statements and loops in assembly language.

An unconditional branch instruction executes by assigning the value of label to the PC. Program execution continues with the instruction located at label.

Unconditional Branch

tabular181

A conditional branch instruction tests a condition. If the condition is true, the PC is reset to label. If the condition is false, the branch instruction executes a no-op.

Zero Tests

tabular202

Relational Tests

tabular220

Notes:

x and y may be type integer or character and may be variables or constants.

All branch instructions can be constructed using branch on zero.

Redundant branch instructions are included for convenience.

Examples:

  1. b next

    is equivalent to

    beqz 0, next

  2. beq x, y, equal

    can be written as:

    sub t, x, y
    beqz t, equal

  3. blt x, y, label

    is the same as:

    bge y, x, label



Mitch Roth
Wed Oct 9 13:38:30 ADT 1996