pub enum Instruction {
Jump(Value),
RelativeJump(Value),
Negate(Value),
Store(Value),
Subtract(Value),
Test,
Stop,
}
Expand description
Represents all the instructions.
Variants§
Implementations§
Source§impl Instruction
impl Instruction
Sourcepub fn parse(instruction: &str) -> Result<Instruction, InstructionError>
pub fn parse(instruction: &str) -> Result<Instruction, InstructionError>
Parses Baby asm instruction & operands using modern notation
§Possible Instruction
Asm | Description |
---|---|
JMP # | Jump to the instruction at the address obtained from the specified memory address # (absolute unconditional jump) |
JRP # | Jump to the instruction at the program counter plus (+) the relative value obtained from the specified memory address # (relative unconditional jump) |
LDN # | Take the number from the specified memory address #, negate it, and load it into the accumulator |
STO # | Store the number in the accumulator to the specified memory address # |
SUB # | Subtract the number at the specified memory address # from the value in accumulator, and store the result in the accumulator |
CMP | Skip next instruction if the accumulator contains a negative value |
STP | Stop |
#
is a always a memory address, and will try to be parsed into a Value.
Sourcepub fn parse_ogn(instruction: &str) -> Result<Instruction, InstructionError>
pub fn parse_ogn(instruction: &str) -> Result<Instruction, InstructionError>
Parses Baby asm instructions & operands using original notation
§Possible Instructions
Asm | Description |
---|---|
#, Cl | Jump to the instruction at the address obtained from the specified memory address # (absolute unconditional jump) |
Add #, Cl | Jump to the instruction at the program counter plus (+) the relative value obtained from the specified memory address # (relative unconditional jump) |
-#, C | Take the number from the specified memory address #, negate it, and load it into the accumulator |
c, # | Store the number in the accumulator to the specified memory address # |
SUB # | Subtract the number at the specified memory address # from the value in accumulator, and store the result in the accumulator |
Test | Skip next instruction if the accumulator contains a negative value |
Stop | Stop |
#
is a always a memory address
Sourcepub fn get_operand(&self) -> Value
pub fn get_operand(&self) -> Value
Returns the stored memory address operand of a instruction, returns a 0 if a stop or test.
Sourcepub fn make_instruction(
instr: Instruction,
operand: String,
) -> Result<Instruction, InstructionError>
pub fn make_instruction( instr: Instruction, operand: String, ) -> Result<Instruction, InstructionError>
Tries to parse an operand value expression, combining it with an instruction.
Will return an InstructionError if parsing the operand value fails.
§Parameters
instr
- The instruction to be used.operand
- The operand value expression to be parsed and combined.
Trait Implementations§
Source§impl Clone for Instruction
impl Clone for Instruction
Source§fn clone(&self) -> Instruction
fn clone(&self) -> Instruction
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Instruction
impl Debug for Instruction
Source§impl PartialEq for Instruction
impl PartialEq for Instruction
impl StructuralPartialEq for Instruction
Auto Trait Implementations§
impl Freeze for Instruction
impl RefUnwindSafe for Instruction
impl Send for Instruction
impl Sync for Instruction
impl Unpin for Instruction
impl UnwindSafe for Instruction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more