Next: Programming IFs
Up: SAL & SPIM
Previous: MIPS Memory Layout
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
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
Relational Tests
- 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:
-
- b next
is equivalent to
beqz 0, next
- beq x, y, equal
can be written as:
sub t, x, y
beqz t, equal
- blt x, y, label
is the same as:
bgt y, x, label
CS 301 Class Account
Wed Sep 20 17:20:34 ADT 2000