Enum Instruction

Source
pub enum Instruction {
Show 19 variants AddReg { dr: Reg, sr1: Reg, sr2: Reg, }, AddImm { dr: Reg, sr1: Reg, imm5: SignedWord, }, AndReg { dr: Reg, sr1: Reg, sr2: Reg, }, AndImm { dr: Reg, sr1: Reg, imm5: SignedWord, }, Br { n: bool, z: bool, p: bool, offset9: SignedWord, }, Jmp { base: Reg, }, Jsr { offset11: SignedWord, }, Jsrr { base: Reg, }, Ld { dr: Reg, offset9: SignedWord, }, Ldi { dr: Reg, offset9: SignedWord, }, Ldr { dr: Reg, base: Reg, offset6: SignedWord, }, Lea { dr: Reg, offset9: SignedWord, }, Not { dr: Reg, sr: Reg, }, Ret, Rti, St { sr: Reg, offset9: SignedWord, }, Sti { sr: Reg, offset9: SignedWord, }, Str { sr: Reg, base: Reg, offset6: SignedWord, }, Trap { trapvec: u8, },
}

Variants§

§

AddReg

Fields

§dr: Reg
§sr1: Reg
§sr2: Reg
§

AddImm

Fields

§dr: Reg
§sr1: Reg
§

AndReg

Fields

§dr: Reg
§sr1: Reg
§sr2: Reg
§

AndImm

Fields

§dr: Reg
§sr1: Reg
§

Br

Fields

§offset9: SignedWord
§

Jmp

Fields

§base: Reg
§

Jsr

Fields

§offset11: SignedWord
§

Jsrr

Fields

§base: Reg
§

Ld

Fields

§dr: Reg
§offset9: SignedWord
§

Ldi

Fields

§dr: Reg
§offset9: SignedWord
§

Ldr

Fields

§dr: Reg
§base: Reg
§offset6: SignedWord
§

Lea

Fields

§dr: Reg
§offset9: SignedWord
§

Not

Fields

§dr: Reg
§sr: Reg
§

Ret

§

Rti

§

St

Fields

§sr: Reg
§offset9: SignedWord
§

Sti

Fields

§sr: Reg
§offset9: SignedWord
§

Str

Fields

§sr: Reg
§base: Reg
§offset6: SignedWord
§

Trap

Fields

§trapvec: u8

Implementations§

Source§

impl Instruction

Source

pub const fn new_add_reg(dr: Reg, sr1: Reg, sr2: Reg) -> Self

Creates a new ADD instruction (Instruction::AddReg) with two register sources. TODO!

println!("{:?}", Instruction::new_add_reg(R0, R1, R2));
Source

pub const fn new_add_imm(dr: Reg, sr1: Reg, imm5: SignedWord) -> Self

Creates a new ADD instruction (Instruction::AddImm) with a register source and a 5 bit signed immediate source ([-16, 16)).

This function will panic at compile time if it is invoked with an immediate value that isn’t in bounds (and if the invocation is in a const context and the resulting value is used). TODO!

println!("{:?}", Instruction::new_add_imm(R0, R1, -16));
println!("{:?}", Instruction::new_add_imm(R0, R1, 15));
println!("{:?}", Instruction::new_add_imm(R0, R1, 16));
println!("{:?}", Instruction::new_add_imm(R0, R1, -17));
Source

pub const fn new_and_reg(dr: Reg, sr1: Reg, sr2: Reg) -> Self

Creates a new AND instruction (Instruction::AndReg) with two register sources. TODO!

println!("{:?}", Instruction::new_and_reg(R0, R1, R2));
Source

pub const fn new_and_imm(dr: Reg, sr1: Reg, imm5: SignedWord) -> Self

Creates a new AND instruction (Instruction::AndImm) with a register source and a 5 bit signed immediate source ([-16, 16)).

This function will panic at compile time if it is invoked with an immediate value that isn’t in bounds (and if the invocation is in a const context and the resulting value is used). TODO!

println!("{:?}", Instruction::new_and_imm(R0, R1, -16));
println!("{:?}", Instruction::new_and_imm(R0, R1, 15));
println!("{:?}", Instruction::new_and_imm(R0, R1, 16));
println!("{:?}", Instruction::new_and_imm(R0, R1, -17));
Source

pub const fn new_br(n: bool, z: bool, p: bool, offset9: SignedWord) -> Self

Creates a new BR instruction (Instruction::Br) with the condition codes to branch on and a 9 bit signed PC-relative offset ([-256, 256)).

This function will panic at compile time if it is invoked with an offset value that isn’t in bounds (and if the invocation is in a const context and the resulting value is used). TODO!

println!("{:?}", Instruction::new_br(true, true, true, 255));
println!("{:?}", Instruction::new_br(true, true, true, -256));
println!("{:?}", Instruction::new_br(true, true, true, 256));
println!("{:?}", Instruction::new_br(true, true, true, -257));
println!("{:?}", Instruction::new_br(false, false, false, -1));
Source

pub const fn new_jmp(base: Reg) -> Self

Creates a new ‘JMP’ instruction ([Instruction::JMP]) with the provided base register. TODO!

println!("{:?}", Instruction::new_jmp(R7));
Source

pub const fn new_jsr(offset11: SignedWord) -> Self

Creates a new JSR instruction ([Instruction::JSR]) with the provided 11 bit signed PC-relative offset ([-1024, 1024)). TODO!

println!("{:?}", Instruction::new_jsr(1023));
println!("{:?}", Instruction::new_jsr(-1024));
println!("{:?}", Instruction::new_jsr(1024));
println!("{:?}", Instruction::new_jsr(-1025));
Source

pub const fn new_jsrr(base: Reg) -> Self

Creates a new ‘JSRR’ instruction ([Instruction::JSRR]) with the provided base register. TODO!

println!("{:?}", Instruction::new_jsrr(R6));
Source

pub const fn new_ld(dr: Reg, offset9: SignedWord) -> Self

Source

pub const fn new_ldi(dr: Reg, offset9: SignedWord) -> Self

Source

pub const fn new_ldr(dr: Reg, base: Reg, offset6: SignedWord) -> Self

Source

pub const fn new_lea(dr: Reg, offset9: SignedWord) -> Self

Source

pub const fn new_not(dr: Reg, sr: Reg) -> Self

Source

pub const fn new_ret() -> Self

Creates a new RET instruction ([Instruction::RET]) (equivalent to a JMP R7). TODO!

println!("{:?}", Instruction::new_ret());
Source

pub const fn new_rti() -> Self

Creates a new RTI instruction ([Instruction::RTI]). TODO!

println!("{:?}", Instruction::new_rti());
Source

pub const fn new_st(sr: Reg, offset9: SignedWord) -> Self

Source

pub const fn new_sti(sr: Reg, offset9: SignedWord) -> Self

Source

pub const fn new_str(sr: Reg, base: Reg, offset6: SignedWord) -> Self

Source

pub const fn new_trap(trapvec: u8) -> Self

Source§

impl Instruction

Source§

impl Instruction

Source

pub fn to_word(&self) -> u16

Trait Implementations§

Source§

impl Clone for Instruction

Source§

fn clone(&self) -> Instruction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Instruction

Source§

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

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

impl<'de> Deserialize<'de> for Instruction

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Instruction

Source§

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

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

impl From<Instruction> for Word

Source§

fn from(ins: Instruction) -> u16

Converts to this type from the input type.
Source§

impl Hash for Instruction

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Instruction

We use the bit representation of Instruction for equality specifically so that Jmp { base: R7 } == RET. However, note that BR != BRnzp.

Source§

fn eq(&self, rhs: &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 Serialize for Instruction

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<u16> for Instruction

Source§

type Error = u16

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

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

Performs the conversion.
Source§

impl Copy for Instruction

Source§

impl Eq 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,