Enum mosis::Instruction[][src]

pub enum Instruction {
    Mov {
        dst: Register,
        src: Register,
    },
    Movi {
        dst: Register,
        imm: u8,
    },
    Add {
        dst: Register,
        x: Register,
        y: Register,
    },
    Sub {
        dst: Register,
        x: Register,
        y: Register,
    },
    Cmp {
        x: Register,
        y: Register,
    },
    Jcc {
        cond: Condition,
        offset: i8,
    },
    Jmp {
        address: Address,
    },
    Call {
        address: Address,
    },
    Ret,
    Nop,
    In {
        dst: Register,
    },
    Out {
        src: Register,
    },
    Mul {
        dst: Register,
        x: Register,
        y: Register,
    },
}

MOSIS instruction type.

All instructions are 16-bits. The first 4 bits represent the opcode, and the remaining 12 bits are used in an instruction-dependent way. Instructions have between 0 and 3 parameters. Most of the instruction names are fixed, except the conditional jump instruction (Jcc).

Variants

Mov

Copy the contents of the src register to the dst register.

Fields of Mov

dst: Registersrc: Register
Movi

Move a number encoded in the instruction (imm)into the dst register.

Fields of Movi

dst: Registerimm: u8
Add

Add two registers x and y, and store the result in the dst register.

Fields of Add

dst: Registerx: Registery: Register
Sub

Subtract register y from register x, (x - y), and store the result in the dst register.

Fields of Sub

dst: Registerx: Registery: Register
Cmp

Compare two registers (using Sub) and set the flags register. Used by Jcc.

Fields of Cmp

x: Registery: Register
Jcc

Jump if a certain condition is true (based on the result of a Cmp).

The conditional jump instruction’s name can be rendered differently depending on the condition (e.g. it becomes JLT when checking for "less than" or JNE when checking for "not equal").

If condition is true, jump to the offset; otherwise, execute the next instruction. The offset is an instruction count, positive or negative based on the sign bit. Offset is from the beginning of the Jcc instruction.

Fields of Jcc

cond: Conditionoffset: i8
Jmp

Jump to a fixed address.

Fields of Jmp

address: Address
Call

Call a function at a fixed address.

More specifically, push the address of the following instruction onto the call stack, then Jmp to the address specified.

Fields of Call

address: Address
Ret

Return from a function.

More specifically, pop the address off the call stack, and Jmp there.

Nop

No operation. Do nothing.

In

Read from external memory or device and store in dst register.

Fields of In

dst: Register
Out

Write contents of src register to external memory or device.

Fields of Out

src: Register
Mul

Multiply two registers x and y and store the result in the dst register.

Fields of Mul

dst: Registerx: Registery: Register

Implementations

impl Instruction[src]

pub fn assemble(&self) -> u16[src]

Assemble an instruction to u16.

pub fn disassemble(inst: u16) -> Result<Self, MOSISError>[src]

All MOSIS instructions are 16 bits, but endianness is not specified in the documentation, so disassembly simply takes a u16 to skirt around this ambiguity.

Trait Implementations

impl Debug for Instruction[src]

impl Display for Instruction[src]

impl Eq for Instruction[src]

impl PartialEq<Instruction> for Instruction[src]

impl StructuralEq for Instruction[src]

impl StructuralPartialEq for Instruction[src]

impl TryFrom<u16> for Instruction[src]

type Error = MOSISError

The type returned in the event of a conversion error.

Auto Trait Implementations

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> From<T> for T[src]

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

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.