[][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.

FFFFNameCountDescription
0000ADD1Addition of register X and register Y
0001SUB1Subtraction of register Y from register X (X-Y)
0010ADDC1Addition of register X and register Y, using the carry bit from F (X+Y+C)
0011SUBC1Subtraction of register Y from register X (X-Y), using the carry bit from F (X-Y-C)
0100OR1Bitwise OR
0101XOR1Bitwise XOR
0110AND1Bitwise AND
0111NOT1Bitwise NOT (unary operation)
1DTT8Shift or Rotate, see section below (unary operation)

Variants

Add

Addition of register X and register Y

Sub

Subtraction of register Y from register X (X-Y)

AddC

Addition of register X and register Y, using the carry bit from F

SubC

Subtraction of register Y from register X (X-Y), using the carry bit from F

Or

Bitwise OR

Xor

Bitwise XOR

And

Bitwise AND

Not

Bitwise NOT

ShiftOrRotate

Shift or Rotate, see member doc

Fields of ShiftOrRotate

d: AluOperationShiftOrRotateDirectiontt: AluOperationShiftOrRotateType

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]

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]

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]

type Error = ()

The type returned in the event of a conversion error.

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Send + Sync + Any
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.