Krolyxon
Commit 68d8540

Branches

Tags

Refs →

bench51srcinstructions.rs

32 lines · 656 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 HLT = 0xFF,
16}
17
18impl Instruction {
19 pub fn opcode_name(op: u8) -> &'static str{
20 match op {
21 0x01 | 0x08 => "MOV",
22 0x02 | 0x0A => "ADD",
23 0x03 | 0x0B => "SUB",
24 0x04 => "JMP",
25 0x05 => "JZ",
26 0x06 => "JNZ",
27 0x07 | 0x09 => "CMP",
28 0xFF => "HLT",
29 _ => "???",
30 }
31 }
32}