import java.awt.*; /*********************************************************************** * File: ExtendedALU.java * Aurthor: Dr. Dalton R. Hunkins * Computer Science Department * St. Bonaventure University * Date: November 2008 * * Purpose: * The file is a stub that allows the reader/programmer to extend * the ALU 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 ExtendedALU extends ALU { private DataLine aluControl, input1, input2, result, zero; private DataPath parent; /*********************************************************************** The Data Lines are aluControl - the line coming from the ALU Control unit input1 - the line coming from the Registers input2 - the line coming from the Mux result - the output line going from the ALU to Data Memory zero - the output line going to the And gate and carries either "0" or "1" ***********************************************************************/ public ExtendedALU(double x[], double y[], int n, Color color, String label, String name, DataLine aluControl, DataLine input1, DataLine input2, DataLine result, DataLine zero, DataPath parent) { super(x, y, n, color, label, name, aluControl, input1, input2, result, zero); this.input1 = input1; this.input2 = input2; this.aluControl = aluControl; this.result = result; this.zero = zero; this.parent = parent; } public void execute() { int operation = (int) hexStringToUnsigned(aluControl.getValue()); int signedNumber1 = hexStringToSigned(input1.getValue()); int signedNumber2 = hexStringToSigned(input2.getValue()); /********************************************************************* INSTRUCTIONS FOR LAB C Currently, the method is implemented by the call super.execute() as seen with the code written below. However, the parent super does nothing with the extensions. Therefore, you must write your code here for those extensions. In particular, super handles the aluControl values 0, 1, 2, 6 and 7. For this lab, you must write code to handle the following aluControl input value (stored in operation) by placing appropriate values on the output lines this.result and this.zero aluControl = A -> bne (Note: nothing more needs to be done here for the MIPS operators addi, andi, ori and xori. WHY?) To accomplish your task, you will need to do the appropriate computations and make the appropriate decision for bne as to the values you place on the output lines. For either of these lines, you make a call to the following method 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 The value you place on the line this.result must be a String of eight hex digits. You may want to use the following method in this case. 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 In the case of the output line this.zero, you will be making either of the following calls this.zero.setValue("0"); or this.zero.setValue("1"); Keep in the note on "hacking" the appropriate that was given in the lab writeup. **********************************************************************/ super.execute(); } }