Enum AsmInstr

Source
pub enum AsmInstr {
Show 25 variants ADD(Reg, Reg, ImmOrReg<5>), AND(Reg, Reg, ImmOrReg<5>), BR(CondCode, PCOffset<i16, 9>), JMP(Reg), JSR(PCOffset<i16, 11>), JSRR(Reg), LD(Reg, PCOffset<i16, 9>), LDI(Reg, PCOffset<i16, 9>), LDR(Reg, Reg, IOffset<6>), LEA(Reg, PCOffset<i16, 9>), NOT(Reg, Reg), RET, RTI, ST(Reg, PCOffset<i16, 9>), STI(Reg, PCOffset<i16, 9>), STR(Reg, Reg, IOffset<6>), TRAP(TrapVect8), NOP(PCOffset<i16, 9>), GETC, OUT, PUTC, PUTS, IN, PUTSP, HALT,
}
Expand description

An enum representing all of the possible instructions in LC-3 assembly code.

The variants in this enum represent instructions before assembly passes.

For instructions that map to bytecode (i.e., the hex representation of assembly instructions), refer to sim::SimInstr.

Variants§

§

ADD(Reg, Reg, ImmOrReg<5>)

An ADD instruction.

§Operation

Evaluates the two operands, adds them, and stores the result to the destination register (DR). This also sets the condition code for the LC-3 machine.

§Syntax

  • ADD DR, SR1, SR2
  • ADD DR, SR1, imm5
§

AND(Reg, Reg, ImmOrReg<5>)

An AND instruction.

§Operation

Evaluates the two operands, bitwise ANDs them, and stores the result to the destination register (DR). This also sets the condition code for the LC-3 machine.

§Syntax

  • AND DR, SR1, SR2
  • AND DR, SR1, imm5
§

BR(CondCode, PCOffset<i16, 9>)

A BR instruction.

§Operation

Checks the current condition code and branches to the given PCOffset9 if the condition code matches one of the provided condition codes of the instruction.

§Syntax

  • BR PCOffset9 (equivalent to BRnzp),
  • BRn PCOffset9
  • BRz PCOffset9
  • BRnz PCOffset9
  • BRp PCOffset9
  • BRnp PCOffset9
  • BRzp PCOffset9
  • BRnzp PCOffset9
§

JMP(Reg)

A JMP instruction.

§Operation

Unconditionally jumps to the location stored in the given register (BR).

§Syntax

  • JMP BR
§

JSR(PCOffset<i16, 11>)

A JSR instruction.

§Operation

Jumps to a given subroutine. This is done by storing the current PC into R7, and then unconditionally jumping to the location of the given PCOffset11.

§Syntax

  • JSR PCOffset11
§

JSRR(Reg)

A JSRR instruction.

§Operation

Jumps to a given subroutine. This is done by storing the current PC into R7, and then unconditionally jumping to the location stored in the given register (BR).

§Syntax

  • JSRR BR
§

LD(Reg, PCOffset<i16, 9>)

A LD instruction.

§Operation

Computes an effective address (PC + PCOffset9), accesses the memory at that address, and stores it to the destination register (DR). This also sets the condition code for the LC-3 machine.

§Syntax

  • LD DR, PCOffset9
§

LDI(Reg, PCOffset<i16, 9>)

A LDI instruction.

§Operation

Computes an effective address (mem[PC + PCOffset9]), accesses the memory at that address, and stores it to the destination register (DR). This also sets the condition code for the LC-3 machine.

§Syntax

  • LDI DR, PCOffset9
§

LDR(Reg, Reg, IOffset<6>)

A LDR instruction.

§Operation

Computes an effective address (mem[BR + offset6]), accesses the memory at that address, and stores it to the destination register (DR). This also sets the condition code for the LC-3 machine.

§Syntax

  • LDR DR, BR, offset6
§

LEA(Reg, PCOffset<i16, 9>)

A LEA instruction.

§Operation

Computes an effective address (PC + PCOffset9) and stores it to the destination register (DR).

§Syntax

  • LEA DR, PCOffset9
§

NOT(Reg, Reg)

A NOT instruction.

§Operation

Evaluates the operand, bitwise NOTs them, and stores the result to the destination register (DR). This also sets the condition code for the LC-3 machine.

§Syntax

  • NOT DR, SR
§

RET

A RET instruction.

§Operation

Returns from a subroutine. This is an alias for JMP R7.

§Syntax

  • RET
§

RTI

A RTI instruction.

§Operation

Returns from a trap or interrupt.

§Syntax

  • RTI
§

ST(Reg, PCOffset<i16, 9>)

A ST instruction.

§Operation

Computes an effective address (PC + PCOffset9), and writes the value from the source register (SR) into the memory at that address,

§Syntax

  • ST SR, PCOffset9
§

STI(Reg, PCOffset<i16, 9>)

A STI instruction.

§Operation

Computes an effective address (mem[PC + PCOffset9]), and writes the value from the source register (SR) into the memory at that address,

§Syntax

  • STI SR, PCOffset9
§

STR(Reg, Reg, IOffset<6>)

A STR instruction.

§Operation

Computes an effective address (mem[BR + offset6]), and writes the value from the source register (SR) into the memory at that address,

§Syntax

  • STR SR, BR, offset6
§

TRAP(TrapVect8)

A TRAP instruction.

§Operation

Executes the trap with the given trap vector TrapVect8.

§Syntax

  • TRAP TrapVect8
§

NOP(PCOffset<i16, 9>)

A NOP instruction.

§Operation

Does nothing.

§Syntax

  • NOP
  • NOP LABEL (label is computed, but not used)
  • NOP #99
§

GETC

A GETC instruction.

§Operation

Gets a character from the keyboard, and store it into R0 (with the high 8 bits cleared). This is an alias for TRAP x20.

§Syntax

  • GETC
§

OUT

An OUT instruction.

§Operation

Writes a character from R0[7:0] to the display. This is an alias for TRAP x21.

§Syntax

  • OUT
§

PUTC

A PUTC instruction.

§Operation

Writes a character from R0[7:0] to the display. This is an alias for TRAP x21.

§Syntax

  • PUTC
§

PUTS

A PUTS instruction.

§Operation

Prints characters in consecutive memory locations until a x00 character is read. This starts with the memory location pointed to by the address in R0.

This is an alias for TRAP x22.

§Syntax

  • PUTS
§

IN

An IN instruction.

§Operation

Prompts the user for a character, stores the character into R0 (with the high 8 bits cleared). Additionally, this prints the obtained character onto the display.

This is an alias for TRAP x23.

§Syntax

  • IN
§

PUTSP

A PUTSP instruction.

§Operation

Prints characters (two characters per memory location) until a x00 character is read. This starts with the memory location pointed to by the address in R0. This first prints the character in the low 8 bits, and then the character in the high 8 bits.

This is an alias for TRAP x24.

§Syntax

  • PUTSP
§

HALT

A HALT instruction.

§Operation

Stops execution of the program. This is an alias for TRAP x25.

§Syntax

  • HALT

Implementations§

Source§

impl AsmInstr

Source

pub fn into_sim_instr( self, pc: u16, sym: &SymbolTable, ) -> Result<SimInstr, AsmErr>

Converts an ASM instruction into a simulator instruction (SimInstr) by resolving offsets and erasing aliases.

Parameters:

  • pc: PC increment
  • sym: The symbol table

Trait Implementations§

Source§

impl Clone for AsmInstr

Source§

fn clone(&self) -> AsmInstr

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 AsmInstr

Source§

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

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

impl Display for AsmInstr

Source§

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

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

impl Hash for AsmInstr

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 Parse for AsmInstr

Source§

fn parse(parser: &mut Parser) -> Result<Self, ParseErr>

Attempt to convert the next sequence of tokens in the parser’s state into a component. Read more
Source§

impl PartialEq for AsmInstr

Source§

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

Source§

impl StructuralPartialEq for AsmInstr

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> 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> 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V