Jump and Branch Instructions (Cont.)

j label         or         b label
Unconditionally jumps to a specified location.

beq rs, rt, label         # branch on equal
Branches to the specified label when the contents of rs equal the contents of rt, or it can branch when the contents of rs equal the immediate value.

bne rs, rt, label         # branch on not equal
Branches to the specified label when the contents of rs do not equal the contents of rt, or it can branch when the contents of rs do not equal the immediate value.

blt rs, rt, label         # branch on less
Branches to the label when the contents of rs are less than the contents of rt, or it can branch when the contents of rs are less than the immediate value. The comparison treats the comparands as signed 32-bit values.
Unconditional Jump beq Arithmetic Series
       .text 
       b   next
       li  $a0, 1
       j   put 
 next: li  $a0, 2
 put:  li  $v0, 1
       syscall
       .text 
       li   $t0, 0xFF
       li   $t1, -1
       beq  $t0, $t1, T
       li   $a0, 1
       j    put
 T:    li   $a0, 2
 put:  li   $v0, 1
       syscall
     .text
     li   $v0, 5
     syscall
     # input ≥ 0
     li   $a0, 0 
 L1:  
     add  $a0, $a0, $v0
     sub  $v0, $v0, 1
     j    L1
 L2: li   $v0, 1
     syscall
Output Output Output







1+2+3+...+input





      “There are no ordinary moments.”    
      ― Dan Millman, Way of the Peaceful Warrior: A Book That Changes Lives