extern crate um;
use um::instruction::{Instruction, ParsingError};
use std::io::Read;

fn main() {
  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 {
    Ok(x) => {
      println!("{}", x.fmt());
      true
    },
    Err(ParsingError) => {
      println!("parsingerror");
      false
    }
  }
}
