Since the control unit takes one input which is opCode, Jr and other R type instructions passes to 000000 to control unit. But for Jr, RegWrite must be 0. How does the control unit differentiate between Jr and the other R-type instructions if they have the same opCode? Do I need to pass funct code to control unit?
I'm working on a Mips Datapath simulator. I have implemented the control unit using a logic design I found in a Computer Architecture lecture notes from a university. You can ignore the AluOp for now.
this.outputs[0].changeValue(opCode == "000000"); // regdest
this.outputs[1].changeValue(opCode == "000010" || opCode == "000011"); //jump
this.outputs[2].changeValue(opCode == "000100"); //branch
this.outputs[3].changeValue(opCode == "100011"); //memread
this.outputs[4].changeValue(opCode == "100011"); // memtoreg
this.outputs[5].changeValue(
["000000"].includes(opCode)
? "10"
: ["100011", "101011"].includes(opCode)
? "00"
: opCode == "000100"
? "01"
: "11" //X
); //aluop
this.outputs[6].changeValue(opCode == "101011"); //memwrite
this.outputs[7].changeValue(opCode != "000000" && opCode != "000100"); //alusrc
this.outputs[8].changeValue(
!["101011", "000010", "000100"].includes(opCode)
); //regwrite
Here is the current version of the simulator: https://saliherdemk.github.io/Mips-Datapath-Simulator/
I searched for a more complex, geniune logic for control unit but I didn't find. Standard datapath needs to modification for JR instruction but I didn't find anything about inside of the control unit.
Edit
Jr datapath looks like this. But since opCode is same it jumps to address in the rd register for all R type instructions. Do we need to pass func code to the control unit?

The
jrinstruction does not use therdfield.Thus, for that instruction the
rdfield should have0, so even ifRegWritewere true, it would be the "zero register" that is written. I believe that is the case for all the R-type instructions, including multiplication/division, mfhi, mthi, etc.. — that therdfield will be 0, when the instruction does not write a register.Since you have to be able to handle (i.e. ignore) writes to the zero register, as in
add $0, $1, $1, for example, you might simply handle thejrthe same way knowing therdfield is zero.You may rely on that or choose not to, ask your coursework.
From https://www.cs.cmu.edu/afs/cs/academic/class/15740-f97/public/doc/mips-isa.pdf, A 4.2 Instruction encoding Picture:
In response to the diagram that has been edited to support
jr:That's quite the diagram! It is missing the traditional circuitry for
jandjal, and seems to have taken over theJumpmux forjr. The following diagram shows the more traditionally used MIPS datapath, which includesjandjalbut notjr.IMHO, they should have started with the
j/jalcircuitry as per my reference, and then added yet another mux forjr— but either way, that last mux needs to choose betweenjrand everything else, so, yes, it will need additional treatment to work properly — your diagram is effectively broken as is.Yes, it could be that the
Controltakes the extra bits (i.e.funct).Or — and I would probably choose this — it could be treated like
ALU control, which already takes thosefunctbits along withALUOpfromControl(which has an indication of R-Type instructions.)The
ALUOphas a way to tellALU controlto use thefunctbits (whenALUOP=2, then it consults thefunctbits), which is what is needed to check forjrvs. any other R-Type.In fact, there's really no reason to duplicate
ALU control, what I would do is simply change theJumpRegcontrol signal to come from theALU controlrather than directly fromControl, which as you are pointing out doesn't have enough information to properly work that end mux. However,ALU controlhas all the information it needs to understandjrvs. all else, so I say that's whereJumpRegshould come from.It is broken and needs something, and so I'd change
JumpRegto originate fromALU controlinstead ofControl. As for the internals ofALU control, this would then require adding new logic to theALUOptable, namely a row and a column. The new row for matchingjrbyALUOp=2 andfunct=jr, and the new column for theJumpRegmux control signal value, e.g. output of zero unlessjr, then 1. I also probably renameALU controltoSecondary Controlor something else more general.