private void Work(string func) { Device pre = new Device(); Instruction instr = new Instruction(); Device post = new Device(); pre.Reg[0].Value = Convert.ToInt32(txtInitREG0.Text); pre.Reg[1].Value = Convert.ToInt32(txtInitREG1.Text); pre.Reg[2].Value = Convert.ToInt32(txtInitREG2.Text); pre.Reg[3].Value = Convert.ToInt32(txtInitREG3.Text); instr.OpCode = Convert.ToInt32(txtInstrOp.Text); instr.Values[0] = Convert.ToInt32(txtInstrVal1.Text); instr.Values[1] = Convert.ToInt32(txtInstrVal2.Text); instr.Values[2] = Convert.ToInt32(txtInstrVal3.Text); switch (func) { case "ADDR": post = OpCodes.ADDR(pre, instr); break; case "ADDI": post = OpCodes.ADDI(pre, instr); break; case "MULR": post = OpCodes.MULR(pre, instr); break; case "MULI": post = OpCodes.MULI(pre, instr); break; case "BANR": post = OpCodes.BANR(pre, instr); break; case "BANI": post = OpCodes.BANI(pre, instr); break; case "BORR": post = OpCodes.BORR(pre, instr); break; case "BORI": post = OpCodes.BORI(pre, instr); break; case "SETR": post = OpCodes.SETR(pre, instr); break; case "SETI": post = OpCodes.SETI(pre, instr); break; case "GTIR": post = OpCodes.GTIR(pre, instr); break; case "GTRI": post = OpCodes.GTRI(pre, instr); break; case "GTRR": post = OpCodes.GTRR(pre, instr); break; case "EQIR": post = OpCodes.EQIR(pre, instr); break; case "EQRI": post = OpCodes.EQRI(pre, instr); break; case "EQRR": post = OpCodes.EQRR(pre, instr); break; } txtFinalREG0.Text = post.Reg[0].Value.ToString(); txtFinalREG1.Text = post.Reg[1].Value.ToString(); txtFinalREG2.Text = post.Reg[2].Value.ToString(); txtFinalREG3.Text = post.Reg[3].Value.ToString(); }
static void RunWork(bool dayB = false) { Device device = new Device(); if (dayB) { device.Reg[0].Value = 1; } int _ptr = -1; long iterations = 0; /* * Register a = device.Reg[0]; * Register b = device.Reg[1]; * Register c = device.Reg[2]; * Register d = device.Reg[3]; * Register e = device.Reg[4]; * Register f = device.Reg[5]; * Register ip = device.Reg[instructionPointerRegister]; * * a.Value = 0; * b.Value = 867; * c.Value = 3; * d.Value = 1; * e.Value = 0; * f.Value = 10; */ try { sw.Start(); while (_ptr < instrList.Count) { iterations++; _ptr = device.Reg[instructionPointerRegister].Value; /* * if (instrList[_ptr].OpCode == (int)EOpCode.ADDI) * { * device = OpCodes.ADDI(device, instrList[_ptr], true); * } * * else if (instrList[_ptr].OpCode == (int)EOpCode.ADDR) * { * device = OpCodes.ADDR(device, instrList[_ptr], true); * } * * else if (instrList[_ptr].OpCode == (int)EOpCode.SETI) * { * device = OpCodes.SETI(device, instrList[_ptr], true); * } * * else if (instrList[_ptr].OpCode == (int)EOpCode.SETR) * { * device = OpCodes.SETR(device, instrList[_ptr], true); * } * * else * { * //throw new ArgumentException((EOpCode)instrList[_ptr].OpCode + " is not a valid OpCode for this run."); * } */ switch (instrList[_ptr].OpCode) { case 0: OpCodes.EQIR(device, instrList[_ptr], true); break; case 1: OpCodes.BORR(device, instrList[_ptr], true); break; case 2: OpCodes.ADDR(device, instrList[_ptr], true); break; case 3: OpCodes.GTRI(device, instrList[_ptr], true); break; case 4: OpCodes.MULI(device, instrList[_ptr], true); break; case 5: OpCodes.GTIR(device, instrList[_ptr], true); break; case 6: OpCodes.MULR(device, instrList[_ptr], true); break; case 7: OpCodes.BANR(device, instrList[_ptr], true); break; case 8: OpCodes.BORI(device, instrList[_ptr], true); break; case 9: OpCodes.EQRI(device, instrList[_ptr], true); break; case 10: OpCodes.EQRR(device, instrList[_ptr], true); break; case 11: OpCodes.BANI(device, instrList[_ptr], true); break; case 12: OpCodes.SETR(device, instrList[_ptr], true); break; case 13: OpCodes.GTRR(device, instrList[_ptr], true); break; case 14: OpCodes.ADDI(device, instrList[_ptr], true); break; case 15: OpCodes.SETI(device, instrList[_ptr], true); break; } //File.AppendAllText("dump.log", device.ToString() + Environment.NewLine); //values += device.ToString() + Environment.NewLine; //File.AppendAllText("dump.log", device.ToString() + " " + instrList[_ptr].ToString() + Environment.NewLine); //else if (device.Reg[instructionPointerRegister].Value + 1 < instrList.Count) { device.Reg[instructionPointerRegister].Value++; } else { break; } } sw.Stop(); //File.AppendAllText("dump.log", values); MessageBox.Show("Program complete in " + sw.ElapsedMilliseconds + "ms (" + sw.ElapsedTicks + " ticks) running " + iterations + " instructions." + Environment.NewLine + device.ToString()); } catch (ArgumentException ae) { MessageBox.Show(ae.Message); } catch (TypeInitializationException typeex) { MessageBox.Show(typeex.Message); } catch (Exception ex) { throw ex; } }