Пример #1
0
 public InstructionJump(Instruction instruction)
 {
     this.opCode = instruction.opCode;
     this.format = instruction.format;
     this.parameter = instruction.parameter;
     this.Address = Convert.ToInt32(instruction.parameter, 2);
 }
Пример #2
0
 public InstructionIO(Instruction instruction)
 {
     this.opCode = instruction.opCode;
     this.format = instruction.format;
     this.parameter = instruction.parameter;
     this.Reg1 = Convert.ToInt32(instruction.parameter.Substring(0, 4), 2);
     this.Reg2 = Convert.ToInt32(instruction.parameter.Substring(4, 4), 2);
     this.Address = Convert.ToInt32(instruction.parameter.Substring(8, instruction.parameter.Length - 8), 2);
 }
 public InstructionBranchAndImmediate(Instruction instruction)
 {
     this.opCode = instruction.opCode;
     this.format = instruction.format;
     this.parameter = instruction.parameter;
     this.BReg = Convert.ToInt32(instruction.parameter.Substring(0, 4), 2);
     this.DReg = Convert.ToInt32(instruction.parameter.Substring(4, 4), 2);
     this.Address = Convert.ToInt32(instruction.parameter.Substring(8, this.parameter.Length - 8), 2);
 }
Пример #4
0
 public InstructionArithmetic(Instruction instruction)
 {
     this.opCode = instruction.opCode;
     this.format = instruction.format;
     this.parameter = instruction.parameter;
     this.SReg1 = Convert.ToInt32(instruction.parameter.Substring(0, 4), 2);
     this.SReg2 = Convert.ToInt32(instruction.parameter.Substring(4, 4), 2);
     this.DReg = Convert.ToInt32(instruction.parameter.Substring(8, 4), 2); ;
 }
Пример #5
0
 private void execute()
 {
     string format = currentInstruction.format;
     if (currentInstruction.opCode.Equals("010011"))//nop
     {
         //do nothing
     }
     else if (format.Equals("00"))
     {
         currentInstruction = new InstructionArithmetic(currentInstruction);
         Arithmetic();
     }
     else if (format.Equals("01"))
     {
         currentInstruction = new InstructionBranchAndImmediate(currentInstruction);
         BranchAndImmidiate();
     }
     else if (format.Equals("10"))
     {
         currentInstruction = new InstructionJump(currentInstruction);
         Jump();
     }
     else if (format.Equals("11"))
     {
         currentInstruction = new InstructionIO(currentInstruction);
         InputOutput();
     }
     else
     {
         throw new InvalidOperationException("Instruction format is invalid");
     }
 }
Пример #6
0
 private void decode()
 {
     int length;
     Console.Out.WriteLine(programCache.Trim());
     Dispatcher dis = Dispatcher.GetInstance();
     Ram rm = Ram.GetInstance();
     String hexValue = programCache.Trim().Substring(2);
     String binary = "";
     for (int i = 0; i < hexValue.Length; i++)
     {
         binary += hextobinary(hexValue[i]);
     }
     currentInstruction = new Instruction(binary);
     length = binary.Length;
 }