pub enum Instruction {
Show 13 variants Mov { dst: Register, src: Register, }, Movi { dst: Register, imm: u8, }, Add { dst: Register, x: Register, y: Register, }, Sub { dst: Register, x: Register, y: Register, }, Cmp { x: Register, y: Register, }, Jcc { cond: Condition, offset: i8, }, Jmp { address: Address, }, Call { address: Address, }, Ret, Nop, In { dst: Register, }, Out { src: Register, }, Mul { dst: Register, x: Register, y: Register, },
}
Expand description

MOSIS instruction type.

All instructions are 16-bits. The first 4 bits represent the opcode, and the remaining 12 bits are used in an instruction-dependent way. Instructions have between 0 and 3 parameters. Most of the instruction names are fixed, except the conditional jump instruction (Jcc).

Variants

Mov

Fields

dst: Register
src: Register

Copy the contents of the src register to the dst register.

Movi

Fields

dst: Register
imm: u8

Move a number encoded in the instruction (imm)into the dst register.

Add

Fields

dst: Register

Add two registers x and y, and store the result in the dst register.

Sub

Fields

dst: Register

Subtract register y from register x, (x - y), and store the result in the dst register.

Cmp

Fields

Compare two registers (using Sub) and set the flags register. Used by Jcc.

Jcc

Fields

cond: Condition
offset: i8

Jump if a certain condition is true (based on the result of a Cmp).

The conditional jump instruction’s name can be rendered differently depending on the condition (e.g. it becomes JLT when checking for “less than” or JNE when checking for “not equal”).

If condition is true, jump to the offset; otherwise, execute the next instruction. The offset is an instruction count, positive or negative based on the sign bit. Offset is from the beginning of the Jcc instruction.

Jmp

Fields

address: Address

Jump to a fixed address.

Call

Fields

address: Address

Call a function at a fixed address.

More specifically, push the address of the following instruction onto the call stack, then Jmp to the address specified.

Ret

Return from a function.

More specifically, pop the address off the call stack, and Jmp there.

Nop

No operation. Do nothing.

In

Fields

dst: Register

Read from external memory or device and store in dst register.

Out

Fields

src: Register

Write contents of src register to external memory or device.

Mul

Fields

dst: Register

Multiply two registers x and y and store the result in the dst register.

Implementations

Assemble an instruction to u16.

All MOSIS instructions are 16 bits, but endianness is not specified in the documentation, so disassembly simply takes a u16 to skirt around this ambiguity.

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.