Преглед на файлове

fixing wraparound, also a typo

jmelesky преди 4 години
родител
ревизия
7012e444b9
променени са 1 файла, в които са добавени 5 реда и са изтрити 5 реда
  1. 5 5
      src/main.rs

+ 5 - 5
src/main.rs

@@ -159,10 +159,10 @@ fn um_step(um: &mut UMState, op: UMOp) {
             um.mem[um.regs[a as usize] as usize][um.regs[b as usize] as usize] = um.regs[c as usize]
         },
         UMOp::Add(a, b, c) => {
-            um.regs[a as usize] = um.regs[b as usize] + um.regs[c as usize]
+            um.regs[a as usize] = um.regs[b as usize].wrapping_add(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]
+            um.regs[a as usize] = um.regs[b as usize].wrapping_mul(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]
@@ -175,7 +175,7 @@ fn um_step(um: &mut UMState, op: UMOp) {
             panic!("Halt reached")
         },
         UMOp::Allocate(b, c) => {
-            let new_arr = vec![032; um.regs[c as usize] as usize];
+            let new_arr = vec![0u32; um.regs[c as usize] as usize];
             let new_arr_add = um.mem.len() as u32;
             um.mem.push(new_arr);
             um.arrmap.insert(new_arr_add, new_arr_add as usize);
@@ -217,9 +217,9 @@ fn um_run(masks: HashMap<&str, (u32,u32)>,
         let full_op = parse_instr(&masks, instr);
         //println!("{}", full_op);
 
-        um_step(um, full_op);
-
         um.pc = um.pc+1;
+
+        um_step(um, full_op);
     }
 }