?? extendedalu.java
字號:
import java.awt.*;
/***********************************************************************
* File: ExtendedALU.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 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 LABS B and 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. 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
And for lab C, your code must 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 for lab B and/or lab C, 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).
You will also need to place values on the output lines
this.result and this.zero using the method setValue belonging
to the DataLine class and the inherited utility method
signedToHexString 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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -