Last active
January 11, 2020 07:42
-
-
Save porglezomp/29dad6aadeaa1a7f03a3bb11a4285f7c to your computer and use it in GitHub Desktop.
Rust instructions for ROSE-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Thanks to Jordan Rose: https://twitter.com/UINT_MIN/status/1215832790958100480 | |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
pub enum Op1 { | |
Zero, | |
Lsl1, | |
Lsr1, | |
Asr1, | |
Incr, | |
Decr, | |
Comp, | |
Negt, | |
} | |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
pub enum OpR { | |
Add, | |
Sub, | |
And, | |
Ior, | |
Xor, | |
Lsl, | |
Lsr, | |
Asr, | |
} | |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
pub enum Data { | |
D1, | |
D2, | |
} | |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
pub enum Special { | |
Data(Data), | |
Code, | |
} | |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
pub struct Reg(U3); | |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
pub struct U3(u8); | |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
pub struct AddImm(i8); | |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
pub enum AluI { | |
And(u8), | |
Ior(u8), | |
Xor(u8), | |
Add(AddImm), | |
Rol(U3), | |
Lsl(U3), | |
Lsr(U3), | |
Asr(U3), | |
} | |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
pub enum Inst { | |
Trap, | |
JAbs, | |
CAbs, | |
JOff, | |
COff, | |
Swap(Reg), | |
GetR(Reg), | |
SetR(Reg), | |
Get(Special), | |
Set(Special), | |
Alu1(Op1), | |
IsLt(Reg), | |
AluR(OpR, Reg), | |
LdD(Data, Reg), | |
StD(Data, Reg), | |
AluI(AluI), | |
BEzI(i8), | |
JOfI(i8), | |
COfI(i8), | |
} | |
impl Reg { | |
pub fn new(x: u8) -> Option<Reg> { | |
U3::new(x).map(Reg) | |
} | |
} | |
impl U3 { | |
pub fn new(x: u8) -> Option<U3> { | |
match x { | |
0..=7 => Some(U3(x)), | |
_ => None, | |
} | |
} | |
} | |
impl AddImm { | |
pub fn new(x: i8) -> Option<AddImm> { | |
match x { | |
-64..=127 => Some(AddImm(x)), | |
_ => None, | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment