|
@@ -143,6 +143,65 @@ fn parse_instr(masks_map: &HashMap<&str, (u32,u32)>,
|
|
|
}
|
|
|
|
|
|
|
|
|
+fn um_step(um: &mut UMState, op: UMOp) {
|
|
|
+ match op {
|
|
|
+ UMOp::ConditionalMove(a, b, c) => {
|
|
|
+ if um.regs[c as usize] != 0 {
|
|
|
+ um.regs[a as usize] = um.regs[b as usize]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ UMOp::ArrayIndex(a, b, c) => {
|
|
|
+
|
|
|
+ },
|
|
|
+ UMOp::ArrayAmend(a, b, c) => {
|
|
|
+
|
|
|
+ },
|
|
|
+ UMOp::Add(a, b, c) => {
|
|
|
+ um.regs[a as usize] = um.regs[b as usize] + um.regs[c as usize]
|
|
|
+ },
|
|
|
+ UMOp::Mult(a, b, c) => {
|
|
|
+ um.regs[a as usize] = um.regs[b as usize] * um.regs[c as usize]
|
|
|
+ },
|
|
|
+ UMOp::Div(a, b, c) => {
|
|
|
+ um.regs[a as usize] = um.regs[b as usize] / um.regs[c as usize]
|
|
|
+ },
|
|
|
+ UMOp::NotAnd(a, b, c) => {
|
|
|
+ um.regs[a as usize] = ! (um.regs[b as usize] & um.regs[c as usize])
|
|
|
+ },
|
|
|
+ UMOp::Halt => {
|
|
|
+ println!("\n\n end of program");
|
|
|
+ panic!("Halt reached")
|
|
|
+ },
|
|
|
+ UMOp::Allocate(b, c) => {
|
|
|
+ },
|
|
|
+ UMOp::Abandon(c) => {
|
|
|
+ },
|
|
|
+ UMOp::Output(c) => {
|
|
|
+ print!("{}", um.regs[c as usize] as u8 as char)
|
|
|
+ },
|
|
|
+ UMOp::Input(c) => {
|
|
|
+ },
|
|
|
+ UMOp::Load(b, c) => {
|
|
|
+ },
|
|
|
+ UMOp::Value(a, val) => {
|
|
|
+ um.regs[a as usize] = val
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+fn um_run(masks: HashMap<&str, (u32,u32)>,
|
|
|
+ um: &mut UMState) {
|
|
|
+ loop {
|
|
|
+ let instr = um.mem[um.pc];
|
|
|
+ let full_op = parse_instr(&masks, instr);
|
|
|
+ //println!("{}", full_op);
|
|
|
+
|
|
|
+ um_step(um, full_op);
|
|
|
+
|
|
|
+ um.pc = um.pc+1;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
fn main() {
|
|
|
|
|
|
let mut masks_map: HashMap<&str, (u32,u32)> = HashMap::new();
|
|
@@ -172,16 +231,7 @@ fn main() {
|
|
|
mem: codex
|
|
|
};
|
|
|
|
|
|
-
|
|
|
- loop {
|
|
|
-
|
|
|
- let instr = um.mem[um.pc];
|
|
|
- let full_op = parse_instr(&masks_map, instr);
|
|
|
- println!("{}", full_op);
|
|
|
-
|
|
|
-
|
|
|
- um.pc = um.pc+1;
|
|
|
- }
|
|
|
+ um_run(masks_map, &mut um);
|
|
|
}
|
|
|
|
|
|
|