Пример #1
0
        public void updateViewElements(short nextInstructionPreview, CPU cpu, Memory memory)
        {
            //Base for register value view
            int BASE = 16; //Only supports 2, 8, 10, 16
            String prefix = "0x";
            this.valueA.Text = prefix + (Convert.ToString(cpu.getRegisterValue(0), BASE).PadLeft(8, '0'));
            this.valueB.Text = prefix + (Convert.ToString(cpu.getRegisterValue(1), BASE).PadLeft(8, '0'));
            this.valueAcc.Text = prefix + (Convert.ToString(cpu.getRegisterValue(2), BASE).PadLeft(8, '0'));
            this.valueZero.Text = prefix + (Convert.ToString(cpu.getRegisterValue(3), BASE).PadLeft(8, '0'));
            this.valueOne.Text = prefix + (Convert.ToString(cpu.getRegisterValue(4), BASE).PadLeft(8, '0'));
            this.valuePC.Text = prefix + (Convert.ToString(cpu.getRegisterValue(5), BASE).PadLeft(8, '0'));
            this.valueMAR.Text = prefix + (Convert.ToString(cpu.getRegisterValue(6), BASE).PadLeft(8, '0'));
            this.valueMDR.Text = prefix + (Convert.ToString(cpu.getRegisterValue(7), BASE).PadLeft(8, '0'));
            this.valueTEMP.Text = prefix + (Convert.ToString(cpu.getRegisterValue(8), BASE).PadLeft(8, '0'));
            this.valueIR.Text = prefix + (Convert.ToString(cpu.getRegisterValue(9), BASE).PadLeft(8, '0'));
            this.valueCC.Text = prefix + (Convert.ToString(cpu.getRegisterValue(10), BASE).PadLeft(8, '0'));

            //Show current instruction index
            updateInstructionIndex(cpu.getRegisterValue(5), memory.getInstructions().Count);

            //Show current instruction code
            updateNextInstruction(nextInstructionPreview, cpu.isDone());

            int total = memory.hitCount + memory.missCount;
            this.hitsValue.Text = memory.hitCount + "";
            this.missesValue.Text = memory.missCount + "";
            this.missrateValue.Text = ((float)memory.missCount / total) + "";
            this.hitrateValue.Text = ((float)memory.hitCount / total) + "";
        }
Пример #2
0
 /**
  * There's probably a better way of doing this.. but oh well ;)
  */
 public static void execute(CPU cpu, short opcode, Boolean immediateflag, short operand)
 {
     switch (opcode)
     {
         case 0:
             LDA(cpu, immediateflag, operand);
             break;
         case 1:
             STA(cpu, operand);
             break;
         case 2:
             ADD(cpu, immediateflag, operand);
             break;
         case 3:
             SUB(cpu, immediateflag, operand);
             break;
         case 4:
             MUL(cpu, immediateflag, operand);
             break;
         case 5:
             DIV(cpu, immediateflag, operand);
             break;
         case 6:
             AND(cpu, immediateflag, operand);
             break;
         case 7:
             OR(cpu, immediateflag, operand);
             break;
         case 8:
             SHL(cpu, operand);
             break;
         case 9:
             NOTA(cpu);
             break;
         case 10:
             BA(cpu, operand);
             break;
         case 11:
             BE(cpu, operand);
             break;
         case 12:
             BL(cpu, operand);
             break;
         case 13:
             BG(cpu, operand);
             break;
         case 14:
             NOP();
             break;
         case 15:
             HLT(cpu);
             break;
     }
 }
Пример #3
0
 /*
  * - ADD $m	Add the value in memory to the accumulator
  * - ADD #$val     Add the value to the accumulator
  */
 private static void ADD(CPU cpu, Boolean immediate, short operand)
 {
     short acc = cpu.getRegisterValue(2);
     if (immediate)
     {
         cpu.setRegisterValue(2, (short)(acc + operand));
     }
     else
     {
         short value = (short)cpu.getMemory().getMemoryLocation(operand);
         cpu.setRegisterValue(2, (short)(acc + value));
     }
 }
Пример #4
0
 public static void resetSimulation(GeminiSimForm form)
 {
     if (null != memory && null != cpu)
     {
         Logger.initialize(fileName); //Start logger back up
         Logger.writeLine("Starting simulation with cache type " +
             Settings.cacheOptions[Convert.ToInt32(Settings.getValue("cachetype"))] +
             " and cache size " + Settings.getValue("cachesize"));
         memory = new Memory(Settings.getValue("cachetype"), Convert.ToInt32(Settings.getValue("cachesize")),
             memory.getInstructions());
         cpu = new CPU(memory);
         Simulator.form = form;
         form.updateViewElements(nextInstructionPreview(), cpu, memory);
     }
 }
Пример #5
0
 /*
  * Start a new cpuulation
  */
 public static void startSimulation(String fileName, GeminiSimForm form)
 {
     if (IsValidFile(fileName))
     {
         Simulator.form = form;
         Logger.initialize(fileName); //Start logger
         Logger.writeLine("Starting simulation with cache type " +
             Settings.cacheOptions[Convert.ToInt32(Settings.getValue("cachetype"))] +
             " and cache size " + Settings.getValue("cachesize"));
         Simulator.fileName = fileName;
         memory = new Memory(Settings.getValue("cachetype"), Convert.ToInt32(Settings.getValue("cachesize")),
             readAllLines(fileName));
         cpu = new CPU(memory);
         form.updateViewElements(nextInstructionPreview(), cpu, memory);
     }
     else
     {
         MessageBox.Show("Assembly file should have extension " + OUTPUT_FILE_TYPE, "File Error");
     }
 }
Пример #6
0
 /*
  * - STA $m  Store the accumulator to a memory location
  */
 private static void STA(CPU cpu, short operand)
 {
     int acc = (int)(cpu.getRegisterValue(2)); //Get accumulator value
     cpu.getMemory().setMemoryLocation(operand, acc);
 }
Пример #7
0
 /*
  * - SHL #$val Shift the accumulator by the number of bits to the left
  */
 private static void SHL(CPU cpu, short operand)
 {
     short acc = cpu.getRegisterValue(2);
     cpu.setRegisterValue(2, (short)(acc << operand));
 }
Пример #8
0
 /*
  * - NOTA		Logical "not" of accumulator
  */
 private static void NOTA(CPU cpu)
 {
     short acc = cpu.getRegisterValue(2);
     cpu.setRegisterValue(2, (short)~cpu.getRegisterValue(2));
 }
Пример #9
0
 /*
  * - LDA #$val Sets the accumulator with the value
  * - LDA $m	Sets the accumulator from a memory location
  */
 private static void LDA(CPU cpu, Boolean immediate, short operand)
 {
     if (immediate)
     {
         cpu.setRegisterValue(2, operand);
     }
     else
     {
         cpu.setRegisterValue(2, (short)cpu.getMemory().getMemoryLocation(operand));
     }
 }
Пример #10
0
 /*
  * - HLT           Quit the program (not needed if the last line of the program is the end)
  */
 private static void HLT(CPU cpu)
 {
     cpu.setPC((short)(cpu.getMemory().getInstructionCount()+1));
 }
Пример #11
0
 /*
  * - BL lbl        Branch to label if operation resulted in Negative
  */
 private static void BL(CPU cpu, short operand)
 {
     short acc = cpu.getRegisterValue(2);
     if (acc < 0)
     {
         cpu.setRegisterValue(5, operand);
     }
 }
Пример #12
0
 /*
  * - BA lbl        Always branch to label (goto)
  */
 private static void BA(CPU cpu, short operand)
 {
     cpu.setRegisterValue(5, operand);
 }