0

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?

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

3

The jr instruction does not use the rd field.

Thus, for that instruction the rd field should have 0, so even if RegWrite were 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 the rd field 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 the jr the same way knowing the rd field 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:

The instruction word encoding is shown in pictorial form at the top of the instruction description. This picture shows the values of all constant fields and the opcode names for opcode fields in upper-case. It labels all variable fields with lower-case names that are used in the instruction description. Fields that contain zeroes but are not named are unused fields that are required to be zero. A summary of the instruction formats and a definition of the terms used to describe the contents can be found in CPU Instruction Formats on page A-174.


In response to the diagram that has been edited to support jr:

That's quite the diagram!  It is missing the traditional circuitry for j and jal, and seems to have taken over the Jump mux for jr.  The following diagram shows the more traditionally used MIPS datapath, which includes j and jal but not jr.

Traditional Datapath

IMHO, they should have started with the j/jal circuitry as per my reference, and then added yet another mux for jr — but either way, that last mux needs to choose between jr and 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 Control takes the extra bits (i.e. funct).

Or — and I would probably choose this — it could be treated like ALU control, which already takes those funct bits along with ALUOp from Control (which has an indication of R-Type instructions.)

The ALUOp has a way to tell ALU control to use the funct bits (when ALUOP=2, then it consults the funct bits), which is what is needed to check for jr vs. any other R-Type.

ALUOp Table

In fact, there's really no reason to duplicate ALU control, what I would do is simply change the JumpReg control signal to come from the ALU control rather than directly from Control, which as you are pointing out doesn't have enough information to properly work that end mux.  However, ALU control has all the information it needs to understand jr vs. all else, so I say that's where JumpReg should come from.

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?

It is broken and needs something, and so I'd change JumpReg to originate from ALU control instead of Control.  As for the internals of ALU control, this would then require adding new logic to the ALUOp table, namely a row and a column.  The new row for matching jr by ALUOp=2 and funct=jr, and the new column for the JumpReg mux control signal value, e.g. output of zero unless jr, then 1.  I also probably rename ALU control to Secondary Control or something else more general.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53
  • I watched several jr datapath videos and all of them set regWrite to 0. but I guess that's right. In encoding phase, for jr instruction looks like this 000000 00001 00000 00000 00000 001000 ($1 = 5). So it always tries write to $0. I'll try to implement X(Don't care) logic to those nodes. Probably would be better if Regwrite is X for JR instruction. Thank you! – Salih Erdem Kaymak Jul 08 '23 at 12:12
  • In this logic, JR control signal always true for R type instructions. Let's say we execute add instruction. Jr control signal will be true. Since Jr is true, it will jump to address stored in rs. But it should be go to pc + 4. – Salih Erdem Kaymak Jul 08 '23 at 13:03
  • I'm not familiar with a `jr` control signal (I know about `Jump` signal and `Branch`). Are you referring to some specific datapath diagram? If so, please share. Most of them are incomplete and/or have errors. For example, `jalr` and `jal` capture the return address and write that to `$ra` aka `$31`, but that is never shown. – Erik Eidt Jul 08 '23 at 15:15
  • I'm referring to JumpReg. It allows for jumping to an address obtained from a register. I edited the question and simulation. – Salih Erdem Kaymak Jul 08 '23 at 18:30
  • That's a really good approach! In fact, I really want to keep the simulation as similar as the well-known datapath. That's why I added to additional mux to simulation (see the link above). I'm curious about what's the real world application. If I can't find complete datapath diagram, I'll probably go with the second approach. Thanks a lot! – Salih Erdem Kaymak Jul 08 '23 at 19:39
  • I like your diagram with the added mux to handle both `j` and `jr`. However, you added the new mux *in between* the `Branch` mux logic and the `Jump` mux. This means that you'll need to assert `Jump` and `JumpReg` at the same time for `jr`. Not sure the `Control` can do that, even shifting the `JumpReg` to the `ALU Control`. – Erik Eidt Jul 08 '23 at 22:59
  • Personally, when I make additions to a design, I like to add them to the end of the decision logic, that way all the other/pre-existing logic conditions remain as is and the new one is like an overall override — either does the new behavior -or- the old behavior exactly as was, period, old behavior with no changes. – Erik Eidt Jul 08 '23 at 23:13
  • If you add that new mux *after* the `Jump` mux, it will be under control of the `JumpReg` signal from `ALU Control` alone, and it won't matter if `Jump` is asserted or not, and yet the old behavior will hold when not `JumpReg`/`jr`. – Erik Eidt Jul 08 '23 at 23:16
  • At the beggining, I added to the end of the decision logic. Then I was tackling around but you're right. It should be end of the design or (maybe) the last mux inputs can be switched. I'll take care of them. Also the Alu Control output is 011 for Jr which behaves like X(Implementation : https://electronics.stackexchange.com/questions/672873/alu-control-output-not-return-010-for-addi-instruction/672988#672988). Maybe I can come up with the idea uses this output with the func code. But your's seems easier. – Salih Erdem Kaymak Jul 09 '23 at 10:13