The Datapath for a Branch


A branch (I-type) instruction has three operands such as
   beq  $t1, $t2, offset  # if ($t1==$t2) then go PC+4+offset
where two registers are compared for equality and offset is for an address.

The 16-bit offset is used to compute the branch target address:
The comparison can be done using the ALU by subtraction of the two register operands. If the Zero signal out of the ALU unit is asserted, we know that the two values are equal. The following figure shows the structure of the datapath segment that handles branches.

The datapath for a branch uses the ALU to evaluate the branch condition and a separate adder to compute the branch target as the sum of the incremented PC and the sign-extended, lower 16 bits of the instruction (the branch displacement), shifted left 2 bits.

Control logic is used to decide whether the incremented PC or branch target should replace the PC, based on the Zero output of the ALU.




      Q: What did the water say to the boat?    
      A: Nothing, it just waved.