Adding Jump and Branch to Datapath

Branch
A branch (I-type) instruction has three operands such as

 beq  $t1, $t2, offset
 # branch if $t1 == $t2
 # branch if  rs ==  rt

The ALU output is used to determine whether the PC is written with PC+4 or the branch target address. The five execution steps for the above instruction are

  1. An instruction is fetched and the PC is incremented.

  2. Two registers, $t1 and $t2, are read from the register file.

  3. The ALU performs a subtract on the data values read from the register file to find the result of comparison.

  4. The value of PC+4 is added to the sign-extended, lower 16 bits of the instruction (offset) shifted left by two; the result is the branch target address from the Next PC block.

  5. The Zero result from the ALU is used to decide which adder result to store into the PC.