mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-28 07:28:20 -04:00
refactored the add-sub dependency
This commit is contained in:
parent
a4789afc8c
commit
31cd0d1b4b
@ -29,10 +29,10 @@ public class Add extends Node implements Element {
|
|||||||
private final ObservableValue sum;
|
private final ObservableValue sum;
|
||||||
private final ObservableValue cOut;
|
private final ObservableValue cOut;
|
||||||
private final long mask;
|
private final long mask;
|
||||||
protected ObservableValue a;
|
private ObservableValue a;
|
||||||
protected ObservableValue b;
|
private ObservableValue b;
|
||||||
protected ObservableValue cIn;
|
private ObservableValue cIn;
|
||||||
protected long value;
|
private long value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance
|
* Create a new instance
|
||||||
@ -49,7 +49,19 @@ public class Add extends Node implements Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readInputs() throws NodeException {
|
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
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.neemann.digital.core.arithmetic;
|
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.ElementAttributes;
|
||||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||||
import de.neemann.digital.core.element.Keys;
|
import de.neemann.digital.core.element.Keys;
|
||||||
@ -31,7 +30,7 @@ public class Sub extends Add {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readInputs() throws NodeException {
|
protected long calc(long a, long b, long c) {
|
||||||
value = a.getValue() - b.getValue() - cIn.getValue();
|
return a - b - c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user