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

tabular138

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

tabular159

Relational Tests

tabular177

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:

    bgt y, x, label



CS 301 Class Account
Mon Sep 13 11:15:41 ADT 1999