refactored the add-sub dependency

This commit is contained in:
hneemann 2016-08-20 20:24:29 +02:00
parent a4789afc8c
commit 31cd0d1b4b
2 changed files with 19 additions and 8 deletions

View File

@ -29,10 +29,10 @@ public class Add extends Node implements Element {
private final ObservableValue sum;
private final ObservableValue cOut;
private final long mask;
protected ObservableValue a;
protected ObservableValue b;
protected ObservableValue cIn;
protected long value;
private ObservableValue a;
private ObservableValue b;
private ObservableValue cIn;
private long value;
/**
* Create a new instance
@ -49,7 +49,19 @@ public class Add extends Node implements Element {
@Override
public void readInputs() throws NodeException {
value = a.getValue() + b.getValue() + cIn.getValue();
value = calc(a.getValue(), b.getValue(), cIn.getValue());
}
/**
* Performs the add operation
*
* @param a a
* @param b b
* @param c carry
* @return the result
*/
protected long calc(long a, long b, long c) {
return a + b + c;
}
@Override

View File

@ -1,6 +1,5 @@
package de.neemann.digital.core.arithmetic;
import de.neemann.digital.core.NodeException;
import de.neemann.digital.core.element.ElementAttributes;
import de.neemann.digital.core.element.ElementTypeDescription;
import de.neemann.digital.core.element.Keys;
@ -31,7 +30,7 @@ public class Sub extends Add {
}
@Override
public void readInputs() throws NodeException {
value = a.getValue() - b.getValue() - cIn.getValue();
protected long calc(long a, long b, long c) {
return a - b - c;
}
}