OpCode

Enum OpCode 

Source
pub enum OpCode {
Show 31 variants Add, And, Ashr, Br, Cmp, Jsr, Ldb, Ldr, Mfhi, Mov, Movr, Movt, Mul, Not, Or, Pop, Push, Ret, Ror, Sc, Seg, Shl, Shr, Stb, Str, Sub, Uadd, Ucmp, Umul, Usub, Xor, // some variants omitted
}
Expand description

A mnemonic and associated binary value for encoding an Instruction. These are divided into four broad categories depending on the way they are encoded: Type C, Type S, Type I, Type J. These encoding patterns are described below. Additional documentation on the instructions associated with each opcode is provided on each variant.

Type-C Encoding: 0bMMMMMDDD-CCISOOOO

Type-S Encoding: 0bMMMMMCCI-OOOOOOOO

Type-I Encoding: 0bMMMMMDDD-IIIIIIII

Type-J Encoding: 0bMMMMMCCC-IIIIIIII

Variants§

§

Add

Adds the value in op8 into the register, interpreting both as signed quantities.

(Type-C Encoding)
  ADD[S][C] <reg>, <op8>
§

And

Preforms a bit-wise and operation onto the value in the register.

(Type-C Encoding)
  AND[S][C] <reg>, <uop8>
§

Ashr

Shifts the value in the register by the value in op8, while preserving the sign bit.

(Type-C Encoding)
  ASHR[S][C] <reg>, <uop8>
§

Br

Branches to an offset of the current %ip. Takes extended condition codes (ge, gt, le, lt).

(Type-J Encoding)
  BR[CC] <imm8>
§

Cmp

Compares two values as signed integers and sets corresponding bits in %s.

(Type-C Encoding)
  CMP[C] <reg>, <op8>
§

Jsr

Changes the value of the instruction pointer to a value stored in one of the general-purpose registers.

(Type-C Encoding)
  JSR[C] <reg>
§

Ldb

Loads a byte into regd from address in memory specified by regs. Fills the upper byte with zeroes when loading the value into the register.

(Type-C Encoding)
  LDB[S][C] <regd>, (<regs>)
§

Ldr

Loads a word (2 bytes) from memory into regd from an address specified in regs.

(Type-C Encoding)
  LDR[S][C] <regd>, (<regs>)
§

Mfhi

Moves the value in the %hi register resulting from a multiplication into reg.

(Type-C Encoding)
  MFHI[S][C] <reg>
§

Mov

Moves an immediate value into the lower byte of reg, padding the upper byte with zeroes.

(Type-I Encoding)
  MOV <reg>, <uimm8>
§

Movr

Moves the value of regs into regd.

(Type-C Encoding)
  MOVR[S][C] <regd>, <regs>
§

Movt

Moves an immediate value into the upper byte of reg, doesn’t affect the lower byte.

(Type-I Encoding)
  MOVT <reg>, <uimm8>
§

Mul

Multiplies two signed numbers, storing the lower word of the result in reg, while the rest goes in a special register %hi. Use mfhi to retrieve the value.

(Type-C Encoding)
  MUL[S][C] <reg>, <op4>
§

Not

Performs a bit-wise not operation on the value in reg.

(Type-C Encoding)
  NOT[S][C] <reg>
§

Or

Performs a bit-wise or operation on between the values in reg and uop8, storing the result in reg.

(Type-C Encoding)
  OR[S][C] <reg>, <uop8>
§

Pop

Pops a value off the stack, and stores it in reg. Due to the encoding type, it is possible to pop %r off of the stack.

(Type-S Encoding)
  POP[C] <reg>
§

Push

Pushes the value of uop16 onto the stack. If this value is a register, then even in user mode, %r can be pushed onto the stack.

(Type-S Encoding)
  PUSH[C] <uop16>
§

Ret

Moves the value in %r into the instruction pointer, effectively returning back from a subroutine.

(Type-J Encoding)
  RET[CC]
§

Ror

Shifts the bits of reg by the value of uop8, placing the shifted out bit in the new most significant bit.

(Type-C Encoding)
  ROR[S][C] <reg> <uop8>
§

Sc

Initiates a system call indexed at uimm8 in the interrupt jump table, switching the mode to supervisor.

(Type-J Encoding)
  SC[CC] <uimm8>
§

Seg

Changes the segment portion of the status register to the value contained in uop16, allowing a different part segment in the memory space to be accessed for data storage, inter-process communication, etc…

(Type-S Encoding)
  SEG[C] <uop16>
§

Shl

Shifts the value contained in reg to the left by uop8.

(Type-C Encoding)
  SHL[S][C] <reg>, <uop8>
§

Shr

Shifts the value contained in reg to the right by uop8.

(Type-C Encoding)
  SHR[S][C] <reg>, <uop8>
§

Stb

Stores the lower byte of the value in regs to the address in memory contained in regd, with the segment corresponding to the value in the status register.

(Type-C Encoding)
  STB[C] <regs>, (<regd>)
§

Str

Stores the value in regs to the address in memory contained in regd, with the segment corresponding to the value in the status register.

(Type-C Encoding)
  STR[C] <regs>, (<regd>)
§

Sub

Subtracts the value of the op8 from the value in reg.

(Type-C Encoding)
  SUB[S][C] <reg>, <op8>
§

Uadd

Adds the value of uop8 to the value in reg, treating both as unsigned values.

(Type-C Encoding)
  UADD[S][C] <reg>, <uop8>
§

Ucmp

Compares the value in reg to the value in uop8, treating both as unsigned values.

(Type-C Encoding)
  UCMP[C] <reg>, <uop8>
§

Umul

Multiplies the value in reg with uop8, treating both as unsigned values.

(Type-C Encoding)
  UMUL[S][C] <reg>, <uop8>
§

Usub

Subtracts the value of uop8 from the value in reg, treating both as unsigned values.

(Type-C Encoding)
  USUB[S][C] <reg>, <uop8>
§

Xor

Performs a bit-wise xor between the value in reg and uop8.

(Type-C Encoding)
  XOR[S][C] <reg>, <uop8>

Implementations§

Source§

impl OpCode

Source

pub fn parse(mnem: &str) -> Option<(OpCode, bool, CondCode)>

Parses a mnemonic into an opcode-condition code pair. If no possible combination is found for an input value, then the method will return None.

Trait Implementations§

Source§

impl Clone for OpCode

Source§

fn clone(&self) -> OpCode

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 Codable for OpCode

Source§

fn encode(&self) -> u16

Encodes the instruction or portion thereof.
Source§

fn decode(value: u16, mode: Mode) -> Option<Self>

Decodes the instruction given the current mode of execution.
Source§

impl Debug for OpCode

Source§

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

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

impl Ord for OpCode

Source§

fn cmp(&self, other: &OpCode) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for OpCode

Source§

fn eq(&self, other: &OpCode) -> 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 PartialOrd for OpCode

Source§

fn partial_cmp(&self, other: &OpCode) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for OpCode

Source§

impl Eq for OpCode

Source§

impl StructuralPartialEq for OpCode

Auto Trait Implementations§

§

impl Freeze for OpCode

§

impl RefUnwindSafe for OpCode

§

impl Send for OpCode

§

impl Sync for OpCode

§

impl Unpin for OpCode

§

impl UnwindSafe for OpCode

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.