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.ArrayList;
22
import java.util.List;
23
import org.feup.brunonova.drmips.simulator.exceptions.InvalidCPUException;
24
import org.feup.brunonova.drmips.simulator.mips.Input;
25
import org.feup.brunonova.drmips.simulator.util.Dimension;
26
import org.feup.brunonova.drmips.simulator.util.Point;
29
* Class that represents an AND port with 2 inputs and 1 output with the size of 1 bit.
33
public class And extends SimpleBinaryOperationComponent {
36
* @param id And's identifier.
37
* @param latency The latency of the component.
38
* @param position The component's position on the GUI.
39
* @param in1Id The identifier of first the input.
40
* @param in2Id The identifier of second the input.
41
* @param outId The identifier of the output.
42
* @throws InvalidCPUException If <tt>id</tt> is empty or duplicated.
44
public And(String id, int latency, Point position, String in1Id, String in2Id, String outId) throws InvalidCPUException {
45
super(id, latency, "AND", "and", "and_description", position, new Dimension(30, 30), in1Id, in2Id, outId, 1);
49
protected int operation(int in1, int in2) {
54
protected List<Input> getLatencyInputs() {
55
ArrayList<Input> inList = new ArrayList<Input>();
56
int val1 = getInput1().getValue();
57
int val2 = getInput2().getValue();
58
if (val1 == val2) { // inputs have identical logic values
59
if (val1 == 1) { // both 1; use both
60
inList.add(getInput1());
61
inList.add(getInput2());
62
} else { // both 0; use just the earliest input
63
int lat1 = getInput1().getAccumulatedLatency();
64
int lat2 = getInput2().getAccumulatedLatency();
66
inList.add(getInput1());
68
inList.add(getInput2());
71
} else if (val1 == 1) { // only val2 == 0
72
inList.add(getInput2());
73
} else { // only val1 == 0
74
inList.add(getInput1());