Krolyxon
Commit 3372e77

Branches

Tags

Refs →

bench51srcinstructions.rs

36 lines · 742 B · Rust

1#[repr(u8)]
2#[allow(non_camel_case_types)]
3pub enum Instruction {
4 MOV_RI = 0x01,
5 MOV_RR = 0x08,
6 ADD_RR = 0x02,
7 ADD_RI = 0x0A,
8 SUB_RR = 0x03,
9 SUB_RI = 0x0B,
10 JMP = 0x04,
11 JZ = 0x05,
12 JNZ = 0x06,
13 CMP_RI = 0x07,
14 CMP_RR = 0x09,
15 MUL = 0x0C,
16 DIV = 0x0D,
17 HLT = 0xFF,
18}
19
20impl Instruction {
21 pub fn opcode_name(op: u8) -> &'static str{
22 match op {
23 0x01 | 0x08 => "MOV",
24 0x02 | 0x0A => "ADD",
25 0x03 | 0x0B => "SUB",
26 0x04 => "JMP",
27 0x05 => "JZ",
28 0x06 => "JNZ",
29 0x07 | 0x09 => "CMP",
30 0x0C => "MUL",
31 0x0D => "DIV",
32 0xFF => "HLT",
33 _ => "???",
34 }
35 }
36}