We now examine in detail how the basic pipeline CPU execute branch instructions
Br Cond ------ LD ST BRA Opcode <-------------- Offset -------------------> +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 | 0 | 1 | x | x | y | y | y | y | y | y | y | y | y | y | y | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
The branch condition is encoded as our good old (simple) non-pipelined
CPU:
0 0 = (not used)
0 1 = Branch on Negative
1 0 = Branch on Zero
1 1 = Always Branch
The offset (a sign binary number) is used to compute the final branch destination address:
Br Cond
------
LD ST BRA Opcode <-------------- Offset ------------------->
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
^ ^
| |
+-------------------------------------------+
offset = 10
|
Br Cond
------
LD ST BRA Opcode <-------------- Offset ------------------->
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
^ ^
| |
+-------------------------------------------+
offset = 10
|
At end of the CPU cycle, registers PC1 is updated with the value in PC and IR1 register is updated with the value 0000000001010 (= 4) which is the offset in the branch instruction (these are the values that matter)
Incidently, we need a different mask pattern to extract the branch offset. The following circuit can do the job:
Also, SMDR register will be updated with the value R3 (but R3 will not be used - see next step).
Clearly, fetching values into A, B and D registers were harmless....
If the branch is taken, the select hardware in the MEM stage will send out a control signal to the MUX in the IF to direct the ALUo output into PC.
If the branch is not taken, the select hardware will pick PC+4....
In this case (Branch Always), the ALUo value will be sent to the input of the PC at the start of the 4th step.
Also, at the end of the CPU cycle, the register ALUo1 is updated with PC+Offset. But as you will see, this value will not be used and no harm will be done.
C-enable sent to registers = C-enable AND (NOT branch)