pub struct Alu {
pub x: Signal16,
pub y: Signal16,
pub zx: Signal,
pub nx: Signal,
pub zy: Signal,
pub ny: Signal,
pub f: Signal,
pub no: Signal,
pub out: Signal16,
pub zr: Signal,
pub ng: Signal,
}
Expand description
Arithmetic Logic Unit
Fields
x: Signal16
y: Signal16
zx: Signal
Set x input to zero
nx: Signal
Negates x input
zy: Signal
Set y input to zero
ny: Signal
f: Signal
- False selects the & function
- True selects the + function
no: Signal
Negates the output
out: Signal16
zr: Signal
Whether the output is zero
ng: Signal
Whether the output is negative
Implementations
sourceimpl Alu
impl Alu
sourcepub fn sim(
&mut self,
x: Signal16,
y: Signal16,
zx: Signal,
nx: Signal,
zy: Signal,
ny: Signal,
f: Signal,
no: Signal
) -> (Signal16, Signal, Signal)
pub fn sim(
&mut self,
x: Signal16,
y: Signal16,
zx: Signal,
nx: Signal,
zy: Signal,
ny: Signal,
f: Signal,
no: Signal
) -> (Signal16, Signal, Signal)
Carries out the ALU simulation.
It takes as input two main signals: x
and y
. Then the following:
zx
: Setx
to zero.nx
: Negatex
.zy
: Sety
to zero.ny
: Negatey
.f
:LO
selects the&
functionHI
selects the+
function
no
: Negateout
signal.
It can return one of the following:
0
, 1
, -1
, x
, y
, !x
, !y
, -x
, -y
,
x+1
, y+1
, x-1
, y-1
, x+y
, x-y
, y-x
, x&y
, x|y
,
And two more signals which tell whether the result is zero or negative in this exact order.
pub fn set_x(&mut self, x: Signal16)
pub fn set_y(&mut self, y: Signal16)
pub fn out(&self) -> Signal16
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Alu
impl Send for Alu
impl Sync for Alu
impl Unpin for Alu
impl UnwindSafe for Alu
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more