Enum mosis::Instruction
source · [−]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
Copy the contents of the src
register to the dst
register.
Movi
Move a number encoded in the instruction (imm
)into the dst
register.
Add
Add two registers x
and y
, and store the result in the dst
register.
Sub
Subtract register y
from register x
, (x - y
), and store the result in the dst
register.
Cmp
Jcc
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
Multiply two registers x
and y
and store the result in the dst
register.
Implementations
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
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.