extendedcontrolunit.java

来自「MIPS Simulator assembly languge.」· Java 代码 · 共 124 行

JAVA
124
字号
import java.awt.*;

/***********************************************************************
 *	File:     ExtendedControlUnit.java
 *    Aurthor:  Dr. Dalton R. Hunkins
 *              Computer Science Department
 *              St. Bonaventure University
 *    Date:     17 January 2006
 *
 *    Purpose:
 *       The file is a stub that allows the reader/programmer to extend
 *       the Control Unit within the Data Path Simulator, PathSim, to
 *       handle additional MIPS operators. The extension is accomplished
 *       through adding java code to the method execute. See the lab
 *       instruction comment given below.
 *
 *   Class Modified by:
 ***********************************************************************/   

class ExtendedControlUnit extends ControlUnit {
	private DataLine input;
	private DataLine signal1, signal2, signal3;
	private DataLine signal4, signal5, signal6;
	private DataLine signal7, signal8, signal9;
	private DataPath parent;
	
    public ExtendedControlUnit(double x, double y, double w, double h,
                               Color c, 
	                         String label1, String label2, String name,
                               DataLine input, 
	                         DataLine signal1, DataLine signal2,
                               DataLine signal3, DataLine signal4,
                               DataLine signal5, DataLine signal6,
	                         DataLine signal7, DataLine signal8,
                               DataLine signal9, DataPath parent) {
		super(x, y, w, h, c, label1, label2, name, input,
	            signal1, signal2, signal3, signal4, signal5, signal6,
	            signal7, signal8, signal9);
		this.input = input;
		this.signal1 = signal1;     // RegDist
		this.signal2 = signal2;     // Jump
		this.signal3 = signal3;     // Branch
		this.signal4 = signal4;     // MemRead
		this.signal5 = signal5;     // MemToReg
		this.signal6 = signal6;     // ALUop
		this.signal7 = signal7;     // MemWrite
		this.signal8 = signal8;     // ALUsrc
		this.signal9 = signal9;     // RegWrite
		
		this.parent  = parent;
	}
	
	
	public void executeAdd(){}
	public void executePart1() {}
	public void executePart2(){}
	
	public void execute() {
	   int opCode = (int) hexStringToUnsigned(input.getValue());
           
/*****************************************************************
               INSTRUCTIONS FOR LAB C
   Currently, the method is handled by super.execute() as seen
   by the call written below. Since the parent super does 
   nothing for the opcodes of the extensions to be added, you
   write your code here for those opcodes (or, at least, for
   the ones that you are handling). In particular, replace the
   call to super.execute() with your code for any of the 
   following opcodes (stored in opCode)
	  8 =  8 -> addi
	  C = 12 -> andi
	  D = 13 -> ori
      E = 14 -> xori
      5 =  5 -> bne
   But do not forget that the opcodes 0, 2, 4, 35, and 43 must
   still be handled by the parent class super.
   Your implementation of the extensions must put appropriate 
   values on the 9 control lines this.signal1 through 
   this.signal9. Use the following for the value placed on
   the ALUop line (this.signal6)
	  addi -> 3
	  andi -> 4
      ori  -> 5
      xori -> 6
      bne  -> 7
   But do not forget that values must also be placed on the
   other lines. To accomplish this task, you will need to
   use the method setValue belonging to the DataLine class
   and the inherited utility method signedToHexString. 
   The two methods are described as follows:

   public void setValue(String value) 
	precondition: 
 	   value is any String
	postcondition:
	   value is put on the data line and appears with
	   a mouse click on the line

   protected String signedToHexString(int number, 
                                      int numberOfDigits) {
	precondition:
	   number is any 32 bit integer
       numberOfDigits is any positive integer
	postcondition:
	   a String of numberOfDigits (e.g. 8 digit) is returned. 
       The string is a sequence of hex digits that is 
       equivalent to the 32 bit integer.

    For development/debugging purposes, you may also wish to use the
    the following method:

    parent.displayMessage(String message)
       precondition:
          message is any string
       postcondition:
          the message is displayed in an alert box

*********************************************************************/

         super.execute();	    
     }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?