2
DrMIPS - Educational MIPS simulator
3
Copyright (C) 2013-2014 Bruno Nova <ei08109@fe.up.pt>
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
package org.feup.brunonova.drmips.simulator.mips.components;
21
import java.util.Stack;
22
import org.feup.brunonova.drmips.simulator.exceptions.InvalidCPUException;
23
import org.feup.brunonova.drmips.simulator.mips.Data;
24
import org.feup.brunonova.drmips.simulator.mips.IsSynchronous;
25
import org.feup.brunonova.drmips.simulator.util.Point;
28
* An ALU that supports multiplications and divisions, and contains the <tt>HI</tt> and <tt>LO</tt> "registers".
32
public class ExtendedALU extends ALU implements IsSynchronous {
33
private final Data hi, lo;
34
private final Stack<int[]> states = new Stack<int[]>(); // previous values
38
* @param id ALU's identifier.
39
* @param latency The latency of the component.
40
* @param position The component's position on the GUI.
41
* @param in1Id The identifier of the first input.
42
* @param in2Id The identifier of the second input.
43
* @param controlId The identifier of the control input.
44
* @param outId The identifier of the output
45
* @param zeroId The identifier of the zero output.
46
* @throws InvalidCPUException InvalidCPUException InvalidCPUException If <tt>id</tt> is empty or duplicated.
48
public ExtendedALU(String id, int latency, Point position, String in1Id, String in2Id, String controlId, String outId, String zeroId) throws InvalidCPUException {
49
super(id, latency, position, in1Id, in2Id, controlId, outId, zeroId);
50
setNameKey("extended_alu");
51
setDescriptionKey("extended_alu_description");
58
public void executeSynchronous() {
59
controlALU.doSynchronousOperation(getInput1().getValue(), getInput2().getValue(), this, getControl().getValue());
63
public void pushState() {
64
states.push(new int[] {hi.getValue(), lo.getValue()});
68
public void popState() {
69
if(hasSavedStates()) {
70
int[] val = states.pop();
77
public boolean hasSavedStates() {
78
return !states.empty();
82
public void clearSavedStates() {
87
public void resetFirstState() {
88
while(hasSavedStates())
93
public boolean isWritingState() {
94
return controlALU.isWritingState(getControl().getValue());
98
* Returns the <tt>HI</tt> "register".
99
* @return The <tt>HI</tt> "register".
101
public final Data getHI() {
106
* Returns the <tt>HI</tt> "register".
107
* @return The <tt>HI</tt> "register".
109
public final Data getLO() {
114
* Resets the <tt>HI</tt> and <tt>LO</tt> registers to 0.
116
public final void reset() {