Need help in adding more functionality to MIPS Single Cycle Datapath

user379888 picture user379888 · Sep 18, 2011 · Viewed 8.6k times · Source

I am trying to add jal functionality to the following but I am stuck with how does it work. I know that it stores the old PC+4 value in the $ra register and then transfers the control to the function which transfers back the control by return $ra but how do I implement it in the hardware? enter image description here

Answer

markgz picture markgz · Sep 20, 2011

There are two things you need to do.

  1. Add a mux at the input of the Registers so that the PC+4 value can be selected as the data to be written. With the appropriate control signal this will allow you to write PC+4 as an additional effect of the "jal $ra" instruction.
  2. Implement the return "jr $ra" instruction. You will need to add a mux to the chain of logic that selects the next PC so that "read data 1" from the register file can be selected as the next PC when the instruction is "jr xxx".