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 B 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. Now for Lab B, your code must handle any of the following aluControl input values (stored in operation) by placing appropriate values on the output lines this.result and this.zero aluControl = 3 -> nor aluControl = 4 -> xor aluControl = 5 -> sllv aluControl = 8 -> srav aluControl = 9 -> srlv To accomplish your task, you will need to do the appropriate computations for the operations (this is a simulator and we CAN write the operations in Java versus constructing circuits). The result of the operation will then be placed on the line with 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 Observe that setValue requires a String and that string is the hexadecimal representation of the computed result and is given as eight hex digits. You can use the following available method to handle the necessary conversion. 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 example, if you store the computed integer result in the local variable computedResult, you then make the call this.result.setValue(computedResult, 9); For setting the value on the zero line, we simply make either the call this.zero("0"); or the call this.zero("1"); **********************************************************************/ super.execute(); } }