[−][src]Enum pir_8_emu::isa::instruction::AluOperation
pub enum AluOperation { Add, Sub, AddC, SubC, Or, Xor, And, Not, ShiftOrRotate { d: AluOperationShiftOrRotateDirection, tt: AluOperationShiftOrRotateType, }, }
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][+]
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][+]
impl Hash for AluOperation
[src][+]
impl Into<u8> for AluOperation
[src][+]
impl Ord for AluOperation
[src][+]
impl PartialEq<AluOperation> for AluOperation
[src][+]
impl PartialOrd<AluOperation> for AluOperation
[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,
impl<T> Downcast for T where
T: Any,
[src][+]
T: Any,
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,
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>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,