Branching
machine code
branch
I-type
opcode 000 xxx (xxx = 1, 4, 5, 6, 7)
Note that bgez, bltz have same opcode, but different rt fields
Instruction B31-26 B25-21 B20-16             B15-0
  opcode register s register t immediate
beq $rt, $rs, <offset> 000 100 - - offset
bne $rt, $rs, <offset> 000 101 - - offset
bgtz $rs, <offset> 000 111 - 00000 offset
bgez $rs, <offset> 000 001 (REGIMM) - 00001 (BGEZ) offset
bltz $rs, <offset> 000 001 (REGIMM) - 00000 (BLTZ) offset
blez $rs, <offset> 000 110 - 00000 offset
The dashes are 5-bit encoding of the register number in UB. For example, $r7 is encoded as 00111. The offset is represented in 16-bit 2C.
jump
jr and jalr are R-type instructions.
opcode 000 000, function different
note rd is 31 for jalr (optional second argument can specify reg for return address)
Instruction B31-26 B25-21 B20-16 B15-11 B10-6 B5-0
  opcode register s register t register d shift amount function
jr $rs 000 000 (SPECIAL) - 00000 00000 00000 001 000
jalr $rs 000 000 (SPECIAL) - 00000 11111 00000 100 010
both j and jal are J-type instructions.
Instruction B31-26 B25-0
  opcode   target                     
j <target> 000 010 -
jal <target> 000 011 -