aboutsummaryrefslogtreecommitdiff
path: root/src/instructions.rs
blob: 9f81b9a7f3f0fbc34802fc65c11e92ddf0548f39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#[repr(u8)]
#[allow(non_camel_case_types)]
pub enum Instruction {
    MOV_RI = 0x01,
    MOV_RR = 0x08,
    ADD_RR = 0x02,
    ADD_RI = 0x0A,
    SUB_RR = 0x03,
    SUB_RI = 0x0B,
    JMP = 0x04,
    JZ = 0x05,
    JNZ = 0x06,
    CMP_RI = 0x07,
    CMP_RR = 0x09,
    MUL = 0x0C,
    DIV = 0x0D,
    HLT = 0xFF,
}

impl Instruction {
    pub  fn opcode_name(op: u8) -> &'static str{
        match op {
            0x01 | 0x08 => "MOV",
            0x02 | 0x0A => "ADD",
            0x03 | 0x0B => "SUB",
            0x04 => "JMP",
            0x05 => "JZ",
            0x06 => "JNZ",
            0x07 | 0x09 => "CMP",
            0x0C => "MUL",
            0x0D => "DIV",
            0xFF => "HLT",
            _ => "???",
        }
    }
}