Instruction

Enum Instruction 

Source
pub enum Instruction {
Show 13 variants 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, },
}
Expand description

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

§

Movi

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

Fields

§imm: u8
§

Add

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

§

Sub

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

§

Cmp

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

§

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

§offset: i8
§

Jmp

Jump to a fixed address.

Fields

§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

§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

§

Out

Write contents of src register to external memory or device.

Fields

§

Mul

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

Implementations§

Source§

impl Instruction

Source

pub fn assemble(&self) -> u16

Assemble an instruction to u16.

Source

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

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§

Source§

impl Debug for Instruction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Instruction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Instruction

Source§

fn eq(&self, other: &Instruction) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<u16> for Instruction

Source§

type Error = MOSISError

The type returned in the event of a conversion error.
Source§

fn try_from(value: u16) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Instruction

Source§

impl StructuralPartialEq for Instruction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.