Enum Opcode

Source
pub enum Opcode {
Show 41 variants NOP = 0, ADD = 1, SUB = 2, MPY = 3, DIV = 4, MOD = 5, INS = 6, OTS = 7, INI = 8, OTI = 9, HLT = 10, LDI = 11, MOV = 12, LDA = 13, MVA = 14, LRF = 15, CPT = 16, PSH = 17, POP = 18, INC = 19, DEC = 20, ICP = 21, DCP = 22, JMP = 23, CMP = 24, JNE = 25, JE = 26, JLT = 27, JGT = 28, CHK = 29, JNZ = 30, JZ = 31, CALL = 32, RET = 33, SCMP = 34, SLEN = 35, ORG = 36, IRG = 37, DBG = 38, EXG = 39, RAND = 40,
}
Expand description

Defines various opcodes

Variants§

§

NOP = 0

No operation

§

ADD = 1

Add the values of two registers

§

SUB = 2

Subtract the value of one register from another

§

MPY = 3

Multiply the values of two registers

§

DIV = 4

Divide the value of one register by another

§

MOD = 5

Calculates the value of one register modulus another

§

INS = 6

Reads a string from stdin and puts it into memory pointed to by an argument register

§

OTS = 7

Prints out a string pointed to by an argument register

§

INI = 8

Reads an integer from stdin and puts it into memory pointed to by an argument register

§

OTI = 9

Prints out an integer pointed to by an argument register

§

HLT = 10

Stops execution of a program

§

LDI = 11

Loads an immediate value into a register

§

MOV = 12

Copies the value of one register into another

§

LDA = 13

Loads the word at an address into a register

§

MVA = 14

Loads the word pointed to by a register into another register

§

LRF = 15

Loads the word in a register into memory

§

CPT = 16

Copies the value pointed to by one register into memory pointed to by another

§

PSH = 17

Pushes the value of a register onto the stack

§

POP = 18

Pops the value on top of the stack into a register

§

INC = 19

Increments the value of a register

§

DEC = 20

Decrements the value of a register

§

ICP = 21

Increments the value pointed to by a register

§

DCP = 22

Decrements the value pointed to by a register

§

JMP = 23

Unconditional jump

§

CMP = 24

Compares the values of two registers and sets the proper flags

§

JNE = 25

Jumps if the equals flag is not set

§

JE = 26

Jumps if the equals flag is set

§

JLT = 27

Jumps if the less-than flag is set

§

JGT = 28

Jumps if the greater-than flag is set

§

CHK = 29

Checks a register and sets the proper flags

§

JNZ = 30

Jumps if the zero flag is not set

§

JZ = 31

Jumps if the zero flag is set

§

CALL = 32

Calls a subroutine

§

RET = 33

Returns from a subroutine

§

SCMP = 34

Compares two strings and sets the proper flags

§

SLEN = 35

Takes the length of a string pointed to by a register and puts it into another register

§

ORG = 36

Prints the value of a register to stdout

§

IRG = 37

Reads a value from stdin and puts it into a register

§

DBG = 38

Prints out the values of all registers

§

EXG = 39

Exchanges the values of two registers

§

RAND = 40

Puts a random integer into the argument register

Implementations§

Source§

impl Opcode

Source

pub fn from_id(id: u8) -> Self

Returns an Opcode instance corresponding to a one-byte ID

§Arguments
  • id - The ID matching the desired opcode
§Panics

This method will panic if the argument ID does not match any defined opcode.

Source

pub fn from_name(name: &str) -> Self

Returns an Opcode instance corresponding to a name string

§Arguments
  • name - The name of the desired opcode
§Panics

This method will panic if the argument name does not match any defined opcode

Source

pub fn get_id(&self) -> u8

Returns the ID of the Opcode

Trait Implementations§

Source§

impl Clone for Opcode

Source§

fn clone(&self) -> Opcode

Returns a copy 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 Opcode

Source§

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

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

impl FromPrimitive for Opcode

Source§

fn from_i64(n: i64) -> Option<Self>

Converts an i64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_u64(n: u64) -> Option<Self>

Converts an u64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_isize(n: isize) -> Option<Self>

Converts an isize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_i8(n: i8) -> Option<Self>

Converts an i8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_i16(n: i16) -> Option<Self>

Converts an i16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_i32(n: i32) -> Option<Self>

Converts an i32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_i128(n: i128) -> Option<Self>

Converts an i128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
Source§

fn from_usize(n: usize) -> Option<Self>

Converts a usize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_u8(n: u8) -> Option<Self>

Converts an u8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_u16(n: u16) -> Option<Self>

Converts an u16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_u32(n: u32) -> Option<Self>

Converts an u32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_u128(n: u128) -> Option<Self>

Converts an u128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
Source§

fn from_f32(n: f32) -> Option<Self>

Converts a f32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_f64(n: f64) -> Option<Self>

Converts a f64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
Source§

impl FromStr for Opcode

Source§

type Err = String

Error type for the from_str method

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string and returns an Opcode instance matching the string wrapped in a Result instance

§Arguments
  • s - the string to parse
Source§

impl PartialEq for Opcode

Source§

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

Compares two Opcodes and returns whether they are the same

§Arguments
  • other - The opcode to compare self to
Source§

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

Compares two Opcodes and returns whether they are different

§Arguments
  • other - The opcode to compare self to
Source§

impl Copy 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.