[−][src]Enum pir_8_emu::isa::instruction::AluOperation
Any CPU instruction of the pattern 0011 FFFF
will invoke some function of the ALU.
The four bits FFFF
are the actual operation being performed by the ALU.
The registers X and Y are used as inputs to the ALU (only X for unary operations), and the S register is used to store the result.
ALU operations will also update the F register as noted.
All will set the ZERO flag if the output (register S) is 0000 0000
.
All will set the PARITY flag if the number of high bits are even in the S register.
The ADD, SUB, ADDC, and SUBC operations will set the carry bit in F to carry out value from the adders.
FFFF | Name | Count | Description |
---|---|---|---|
0000 | ADD | 1 | Addition of register X and register Y |
0001 | SUB | 1 | Subtraction of register Y from register X (X-Y) |
0010 | ADDC | 1 | Addition of register X and register Y, using the carry bit from F (X+Y+C) |
0011 | SUBC | 1 | Subtraction of register Y from register X (X-Y), using the carry bit from F (X-Y-C) |
0100 | OR | 1 | Bitwise OR |
0101 | XOR | 1 | Bitwise XOR |
0110 | AND | 1 | Bitwise AND |
0111 | NOT | 1 | Bitwise NOT (unary operation) |
1DTT | 8 | Shift or Rotate, see section below (unary operation) |
Variants
Addition of register X and register Y
Subtraction of register Y from register X (X-Y)
Addition of register X and register Y, using the carry bit from F
Subtraction of register Y from register X (X-Y), using the carry bit from F
Bitwise OR
Bitwise XOR
Bitwise AND
Bitwise NOT
Shift or Rotate, see member doc
Fields of ShiftOrRotate
Methods
impl AluOperation
[src]
pub fn perform(self, lhs: u8, rhs: u8, carry: &mut bool) -> u8
[src]
Perform the ALU operation on the specified operands
Returns 0
and sets carry for reserved ops.
Examples
assert_eq!(AluOperation::Or.perform(0b0001, 0b0100, &mut false), 0b0101); let mut carry = true; assert_eq!(AluOperation::ShiftOrRotate { d: AluOperationShiftOrRotateDirection::Left, tt: AluOperationShiftOrRotateType::Rtc, }.perform(0b0101_0000, 0, &mut carry), 0b1010_0001); assert_eq!(carry, false); let mut carry = false; assert_eq!(AluOperation::Add.perform(0b1001_0000, 0b1010_0101, &mut carry), 0b0011_0101); assert_eq!(carry, true);
Trait Implementations
impl Clone for AluOperation
[src]
fn clone(&self) -> AluOperation
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for AluOperation
[src]
impl Debug for AluOperation
[src]
impl Display for AluOperation
[src]
impl Eq for AluOperation
[src]
impl FromStr for AluOperation
[src]
type Err = ParseInstructionError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
Parse ALU operation in assembly instruction format
The input string must be ASCII and contain no vertical whitespace
Examples
assert_eq!(AluOperation::from_str("XOR"), Ok(AluOperation::Xor)); assert_eq!(AluOperation::from_str("SOR RIGHT ASF"), Ok(AluOperation::ShiftOrRotate { d: AluOperationShiftOrRotateDirection::Right, tt: AluOperationShiftOrRotateType::Asf, }));
impl Hash for AluOperation
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Into<u8> for AluOperation
[src]
impl Ord for AluOperation
[src]
fn cmp(&self, other: &AluOperation) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<AluOperation> for AluOperation
[src]
fn eq(&self, other: &AluOperation) -> bool
[src]
fn ne(&self, other: &AluOperation) -> bool
[src]
impl PartialOrd<AluOperation> for AluOperation
[src]
fn partial_cmp(&self, other: &AluOperation) -> Option<Ordering>
[src]
fn lt(&self, other: &AluOperation) -> bool
[src]
fn le(&self, other: &AluOperation) -> bool
[src]
fn gt(&self, other: &AluOperation) -> bool
[src]
fn ge(&self, other: &AluOperation) -> bool
[src]
impl StructuralEq for AluOperation
[src]
impl StructuralPartialEq for AluOperation
[src]
impl TryFrom<u8> for AluOperation
[src]
Auto Trait Implementations
impl RefUnwindSafe for AluOperation
impl Send for AluOperation
impl Sync for AluOperation
impl Unpin for AluOperation
impl UnwindSafe for AluOperation
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Downcast for T where
T: Any,
[src]
T: Any,
fn into_any(self: Box<T>) -> Box<dyn Any + 'static>
[src]
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
[src]
fn as_any(&self) -> &(dyn Any + 'static)
[src]
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
[src]
impl<T> DowncastSync for T where
T: Send + Sync + Any,
[src]
T: Send + Sync + Any,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,