override public string ToString() { switch (opcode) { case OPCODE.LABEL: return($"[{target}]"); case OPCODE.BSR: case OPCODE.BRF: case OPCODE.BRA: return(opcode.ToString() + " " + target); case OPCODE.PUSHINT: case OPCODE.PUSHBOOL: case OPCODE.POP: case OPCODE.DECL: return(opcode.ToString() + " " + argument.ToString()); case OPCODE.LVAL: case OPCODE.RVALINT: case OPCODE.RVALBOOL: return(opcode.ToString() + " " + argument.ToString() + "(FP)"); case OPCODE.ASSINT: case OPCODE.ASSBOOL: case OPCODE.ADD: case OPCODE.LTINT: case OPCODE.GTINT: case OPCODE.EQINT: case OPCODE.WRITEINT: case OPCODE.WRITEBOOL: case OPCODE.LINK: case OPCODE.UNLINK: case OPCODE.RTS: case OPCODE.END: case OPCODE.NOT: case OPCODE.SUB: case OPCODE.MUL: case OPCODE.DIV: case OPCODE.NEG: return(opcode.ToString() + " "); } throw new NotImplementedException(); }
public override string ToString() { switch (opCode) { case OPCODE.JR: return("JR " + gp_1.ToString()); case OPCODE.LUI: return("LUI " + gp_dest.ToString() + " 0x" + immediate.ToString("X4")); case OPCODE.ADDIU: return("ADDIU " + gp_dest.ToString() + " " + gp_1.ToString() + " 0x" + immediate.ToString("X4")); case OPCODE.JAL: return("JAL 0x" + jump_to_func.ToString("X8")); } return(opCode.ToString()); }
public override string ToString() { switch (QR) { case DNS.QR.Q: return(string.Format("Request: {0}", OPCODE.ToString() )); case DNS.QR.R: return(string.Format("{0}: {1} RD={2} RA={3} {4} {5}", (AA ? "Authoritative Response" : "Non-Authoritative Response"), OPCODE.ToString(), (RD ? "1" : "0"), (RA ? "1" : "0"), RCODE.ToString(), (TC ? "TRUNCATED " : "") )); } // throw new InvalidOperationException("Unexpected QR value."); // CA1065 Do not raise exceptions in unexpected locations return(null); }
public Instruction CreateInstruction(int positionPointer) { int memoryValue = this.Memory[positionPointer]; string opCodeMode = memoryValue.ToString("D5"); OPCODE code = (OPCODE)int.Parse(opCodeMode.Substring(3, 2)); List <MODE> modes = new List <MODE>(); MODE modeParam1; MODE modeParam2; MODE modeParam3; List <int> parameters = new List <int>(); switch (code) { case OPCODE.add: modeParam1 = (MODE)int.Parse(opCodeMode.Substring(2, 1)); modeParam2 = (MODE)int.Parse(opCodeMode.Substring(1, 1)); modeParam3 = (MODE)int.Parse(opCodeMode.Substring(0, 1)); modes.Add(modeParam1); modes.Add(modeParam2); modes.Add(modeParam3); parameters.Add(this.Memory[positionPointer + 1]); parameters.Add(this.Memory[positionPointer + 2]); parameters.Add(this.Memory[positionPointer + 3]); break; case OPCODE.multiply: modeParam1 = (MODE)int.Parse(opCodeMode.Substring(2, 1)); modeParam2 = (MODE)int.Parse(opCodeMode.Substring(1, 1)); modeParam3 = (MODE)int.Parse(opCodeMode.Substring(0, 1)); modes.Add(modeParam1); modes.Add(modeParam2); modes.Add(modeParam3); parameters.Add(this.Memory[positionPointer + 1]); parameters.Add(this.Memory[positionPointer + 2]); parameters.Add(this.Memory[positionPointer + 3]); break; case OPCODE.Input: modeParam1 = (MODE)int.Parse(opCodeMode.Substring(2, 1)); modes.Add(modeParam1); parameters.Add(this.Memory[positionPointer + 1]); break; case OPCODE.Output: modeParam1 = (MODE)int.Parse(opCodeMode.Substring(2, 1)); modes.Add(modeParam1); parameters.Add(this.Memory[positionPointer + 1]); break; case OPCODE.finish: break; default: throw new ArgumentException("Create Instruction: Unkown IntCode: " + code.ToString()); } return(new Instruction(code, modes, parameters)); }