How the pipeline CPU executes add r1,r2,#3

Clock cycle 1: The IF stage fetches the instruction into the IR(ID) register

I have include the instruction code in binary

How the pipeline CPU executes add r1,r2,#3

Start of clock cycle 2: the ID stage fetch all possible source operands

 

How the pipeline CPU executes add r1,r2,#3

End of clock cycle 2: all source operands are fetched - but only R2 and  3  will be used

Notice: the instruction is moved into the IR(EX) register

How the pipeline CPU executes add r1,r2,#3

Start of clock cycle 3: the EX stage operates on the correct source operands

The immediate bit (green bit) = 1 will select the constant 3 for the 2nd source operand.

How the pipeline CPU executes add r1,r2,#3

End of clock cycle 3: the result is stored in ALU Output and the Data Mem Addr registers

Notice: the instruction is moved into the IR(MEM) register

How the pipeline CPU executes add r1,r2,#3

Start of clock cycle 4: the MEM stage does not perform operation for add r1,r2,#3

But: we must forward the result(s) further down the pipeline !!

How the pipeline CPU executes add r1,r2,#3

End of clock cycle 4: the result (R2+3) is stored in the ALU Output1 register

Notice: the instruction is moved into the IR(WB) register

How the pipeline CPU executes add r1,r2,#3

Start of clock cycle 5: the WB stage selects ALU Output 1 as input and update the register R1

 

How the pipeline CPU executes add r1,r2,#3

End of clock cycle 5: the result (R2+3) is stored in the register R1

Notice: the instruction has been into the discarded !! (no longer needed !!!)

DEMO (using Aaron's pipelined CPU)
 

  • Execute this command on a lab machine:

       /home/cs355001/demo/pipeline/1b-ALU-instr+with-const    
      

    Program being executed:

         10  65    // mov r1, #65       R1 = 00000000 01000001
         18  4     // mov r2, #4	  R2 = 00000000 00000100
         26  24    // mov r3, #24	  R3 = 00000000 00011000
         34  2     // mov r4, #2	  R4 = 00000000 00000010
         42  8     // mov r5, #8	  R5 = 00000000 00001000
         58  3     // mov r7, #3	  R7 = 00000000 00000011
         0   0     // nop
         0   0     // nop
         0   0     // nop
         0   0     // nop
         0   0     // nop
         8   83    // add r1,r2,#3     (R1=R2+R3)
                                        R1 := 00000000 00011100