using DisComputer; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 指令数据 /// public class CommandData { //指令内容 public CommandType command; public int num01; public int num02; public int result; /// /// 内存地址 /// public string mem; //具体执行名称 public string ActName; /// /// 指令名称 /// public string Name { get { string _name = "空指令"; switch (command) { case CommandType.Add: _name = "加法指令"; break; case CommandType.Div: _name = "除法指令"; break; case CommandType.Mul: _name = "乘法指令"; break; case CommandType.Sub: _name = "减法指令"; break; } return _name; } } /// /// 返回算式指令 /// public List ActCommandList { get { List _temp = new List(); string[] _tempArr; switch (command) { case CommandType.Add: _tempArr = new string[5] { "mov3","mov3","add","out","halt"}; _temp = new List(_tempArr); break; case CommandType.Div: _tempArr = new string[5] { "mov3", "mov3", "div", "out", "halt" }; _temp = new List(_tempArr); break; case CommandType.Mul: _tempArr = new string[5] { "mov3", "mov3", "mul", "out", "halt" }; _temp = new List(_tempArr); break; case CommandType.Sub: _tempArr = new string[5] { "mov3", "mov3", "sub", "out", "halt" }; _temp = new List(_tempArr); break; } return _temp; } } /// /// 随机干扰指令 /// public List JamCommandList { get { string[] _tempArr = new string[9] { "mov1", "mov2","add","div","mul" , "sub" ,"jmp","jz","in"}; List _temp = new List(_tempArr); return _temp; } } /// /// 设置随机指令集 /// /// mov operations io jmp public void SetRandomCmdType(string type) { if (type.Contains("mov"))//mov指令 { CommandType[] commands = { CommandType.Mov1, CommandType.Mov2, CommandType.Mov3 }; command = commands[Random.Range(0, commands.Length)]; } else if (type.Contains("operations"))//运算指令 { CommandType[] commands = { CommandType.Mul, CommandType.Sub, CommandType.Add ,CommandType.Div}; command = commands[Random.Range(0, commands.Length)]; } else if (type.Contains("IO"))//IO流指令 { CommandType[] commands = { CommandType.Out, CommandType.In }; command = commands[Random.Range(0, commands.Length)]; } else if (type.Contains("jmp"))//条件指令 { CommandType[] commands = { CommandType.Jz, CommandType.Jmp }; command = commands[Random.Range(0, commands.Length)]; } } } public enum CommandType { Null, //加法 Add, //减法 Sub, //乘法, Mul, //除法 Div, //mov1指令 Mov1, //mov2指令 Mov2, //mov3指令 Mov3, //无条件跳转指令 Jmp, //条件跳转指令 Jz, //输入指令 In, //输出指令 Out, //运算式 Operator } /// /// 诺依曼指令数据 /// public class VonNeumann { public static CommandData data; /// /// 指令下标 /// public static int CommandIndex = 0; /// /// 指令正在运行 /// public static bool isRunning = false; /// /// 是否完成 /// public static bool isFinish = false; /// /// 指令操作说明 /// public static string cmdTipInfo = ""; /// /// 当前指令地址 /// public static int curpRegIndex; /// /// 当前mov1 mov2 mem 下标值 /// public static int movMemIndex; /// /// 当前寄存器下标 /// public static int curRexIndex; /// /// 当前指令配置信息 /// public static IIICmdConfig cmdConfig; } /// /// 数据匹对 /// public class MatchVonNeuData { public static int rexIndex = -1; public static int pRegIndex = -1; public static int mem = -1; public static int op01Index = -1; public static int op02Index = -1; }