disas
This commit is contained in:
parent
69d9753fff
commit
3181d2c80d
@ -1,10 +1,32 @@
|
|||||||
extern crate um;
|
extern crate um;
|
||||||
use um::instruction::{Instruction, ParsingError};
|
use um::instruction::{Instruction, ParsingError};
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let i = Instruction::parse(0x81234567);
|
let mut stdin = std::io::stdin().lock();
|
||||||
|
let mut cont = true;
|
||||||
|
while cont {
|
||||||
|
let mut buffer = [0u8; 4];
|
||||||
|
cont = match stdin.read(&mut buffer) {
|
||||||
|
Ok(4) => hdl(buffer),
|
||||||
|
Ok(_) => false,
|
||||||
|
Err(_) => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hdl(buffer: [u8; 4]) -> bool{
|
||||||
|
let num = u32::from_be_bytes(
|
||||||
|
buffer.try_into().unwrap());
|
||||||
|
let i = Instruction::parse(num);
|
||||||
match i {
|
match i {
|
||||||
Ok(x) => println!("Ins {:?}!", x.fmt()),
|
Ok(x) => {
|
||||||
Err(ParsingError) => println!("OOPS")
|
println!("{}", x.fmt());
|
||||||
|
true
|
||||||
|
},
|
||||||
|
Err(ParsingError) => {
|
||||||
|
println!("parsingerror");
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,22 +39,23 @@ const fn u3at(d: u32, pos: u8) -> u3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Instruction {
|
impl Instruction {
|
||||||
pub fn fmt(&self) -> &'static str {
|
pub fn fmt(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Instruction::ConditionalMove(i) => "CMV",
|
Instruction::ConditionalMove(i) => format!("CMV r{}=r{} if r{}", i.
|
||||||
Instruction::ArrayIndex(i) => "IDX",
|
a, i.b, i.c),
|
||||||
Instruction::ArrayAmend(i) => "AMD",
|
Instruction::ArrayIndex(i) => format!("IDX r{}=r{}[r{}]", i.a, i.b, i.c) ,
|
||||||
Instruction::Add(i) => "ADD",
|
Instruction::ArrayAmend(i) => format!("AMD r{}[r{}]=r{}", i.a, i.b, i.c),
|
||||||
Instruction::Multiply(i) => "MUL",
|
Instruction::Add(i) => format!("ADD r{}=r{}+r{}", i.a, i.b, i.c),
|
||||||
Instruction::Divide(i) => "DIV",
|
Instruction::Multiply(i) => format!("MUL r{}=r{}*r{}", i.a, i.b, i.c),
|
||||||
Instruction::NotAnd(i) => "NAD",
|
Instruction::Divide(i) => format!("DIV r{}=r{}/r{}", i.a, i.b, i.c),
|
||||||
Instruction::Halt(i) => "HLT",
|
Instruction::NotAnd(i) => format!("NAD r{}=r{} nand r{}", i.a, i.b, i.c),
|
||||||
Instruction::Allocate(i) => "ALC",
|
Instruction::Halt(i) => format!("HLT"),
|
||||||
Instruction::Abandon(i) => "ABN",
|
Instruction::Allocate(i) => format!("ALC r{} r{}", i.b, i.c),
|
||||||
Instruction::Output(i) => "OUT",
|
Instruction::Abandon(i) => format!("ABN r{}", i.c),
|
||||||
Instruction::Input(i) => "INP",
|
Instruction::Output(i) => format!("OUT r{}", i.c),
|
||||||
Instruction::Load(i) => "LOD",
|
Instruction::Input(i) => format!("INP r{}", i.c),
|
||||||
Instruction::Ortho(i) => "ORT"
|
Instruction::Load(i) => format!("LOD r{}@r{}", i.b, i.c),
|
||||||
|
Instruction::Ortho(i) => format!("ORT r{}={}", i.a, i.v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user