Single Clock Cycle Architecture

MIPS Architecture

ALU Control

R-type instructions have 6 bits in the funct field to control the ALU. The first two bits are the ALUOp to indicate 1 of 3 selection codes. Based on the selection code, the next 4 bits could have a different meaning.

opcodeALUOpfunct fieldoperationALUControl
lw / sw00don't care
always a sum
sum0010
beq01don't care
always a subtraction
sub0110
R-type1010_0000ALUControl decides
based on last 4 bits
0010

Based on the instruction type, we have different behaviours for the funct field and the ALUControl.

#funcfunction
00000AND
10001OR
20010add
60110subtract
70111slt
121100NOR

Control Unit Signals

signalon falseon true
RegDstwrite register number comes from rtwrite register number comes from rd
RegWritethe data is written in in the write register
ALUSrcdata comes from register 2data comes from sign extender (immediate part)
PCSrcnext instruction is PC + 4next instruction is PC + 4 + immediate
MemReadread from memory and put in read data value at address
MemWritedata at address calculated from ALU, is overwritten by data in register 2
MemToRegdata to write in register file comes from ALUdata to write in register file comes from memory

Exercise

Based on the following instructions, write the truth table for the Control Unit, having as input 6 bits (opcode) and as output 9 bits (control signals)

opopcodeRegDstALUSrcMemtoRegRegWriteMemReadMemWriteBranchALUOp
R0000001001X0010
lw100011011110000
sw1010110100X1000
beq00010000X0X0101

Note: the exercise is correct, but there are some places in which we can use don't cares instead of actual values. From here, we can create a PLA with the necessary functions.

Adding New Instructions

j

Let's try to add a j (jump) instruction to the current archtecture.

We must define:

  • it's encoding
  • it's behaviour
  • the functional units we need
  • the flux of information
  • necessary control signals
  • execution time (and wether it impacts the total time)
opcodeimmediate value
00001011011101001001001001100111
\(31-26\)\(25-0\)

The immediate value is the absolute address to which we have to jump to (divided by 4). To get the full address we have to expand the immediate value:

PC + 4 first 4 bitsimmediate valuemultiplication by 4
01101101110100100100100110011100

We have to shift the immediate value by 2, because the instructions are 4 bytes long, so we have to multiply by 4 the absolute address. Then, we get the missing 4 bits from PC + 4, so we stay within the same 256Mb block (the first 4 bits identify the block, so the size of the block is \(2^{28} bit = 2^8 bit * 2^{20} \approx 2^8 * 10^6 \approx 256 Mb \)).

\(PC \leftarrow (PC + 4)[31..28] \ or \ (instruction[25..0] << 2)\)

We also need a jump control signal, to determine wether we are jumping or not, and we have to make sure that we don't write any registers or memory. In pink, the implementation of the j instruction.

Jump Instruction Implementation

jal

The jal (jump and link) instruction is a J-type that does the same thing as j, with the difference that it saves in $ra (register number 31) the current value of the PC + 4.

\( $ra \leftarrow PC + 4 \)

jal Instruction Implementation

jr

It's an I-type instruction, we just have to link whatever value we read from rs and move it into PC.

jr Instruction Implementation

addi

Not all instructions require modifications to the circuitery, like addi.

Exercise

Add to the CPU the R-type instruction jrr rs (jump relative to register) , which jumps to the address (relative to the PC) contained in rs. \(PC \leftarrow PC + 4 + reg[rs]\)

jrr Instruction Implementation

Control Signals

opJrrJumpRegDstALUSrcMemtoRegRegWriteMemReadMemWriteBranchALUOp
jrr10XXX0X0XXX

TODO: execution time and clock