private void loadFileButton_Click(object sender, EventArgs e)
 {
     using (var ofd = new OpenFileDialog())
     {
         if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             try
             {
                 var ipe = new IPE(ofd.FileName);
                 ipe.ParseFile();
             }
             catch (Exception err)
             {
                 // show a dialog with error
             }
         }
     }
 }
Exemplo n.º 2
0
        private void loadFileButton_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        var ipe = new IPE(ofd.FileName);
                        List<string> binary = ipe.ParseFile();
                        myCPU.setNumInstLeft(binary.Count);
                        //for (int i = 0; i < binary.Count; i++)
                        //{
                        //    Console.WriteLine("parser at " + i + ": " + binary[i]);
                       // }
                        List<Int16> finBinary = convert(binary);
                        //ipe.createBinaryTextFile(binary);
                        createBinaryFile(finBinary);
                        myCPU.setBinary(binary);
                        myCPU.setBinary16(finBinary);
                        myCPU.setLabelLocationMap(ipe.getLabelLocationMap());
                        mainMemory.setLabelLocationMap(ipe.getLabelLocationMap());
                        myCPU.getMainMemory().InitializeCache();

                        foreach( KeyValuePair<string, int> kvp in ipe.getLabelLocationMap() )
                        {
                            //Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
                        }
 //                       for (int i = 0; i < ipe.getLabelLocationMap().Count; i++)
   //                     {
     //                       Console.WriteLine("map key: " + ipe.getLabelLocationMap().Keys[i])
       //                 }
         //                   Console.WriteLine("map.keys: " + ipe.getLabelLocationMap());
                        //Console.WriteLine("map.value: " + ipe.getLabelLocationMap().Values);
                        myCPU.PC = 0;
                        myCPU.finished = false;
                        ipe.broken = false;
                    }
                    catch (Exception err)
                    {
                       System.Windows.Forms.MessageBox.Show(err.Message);
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void loadFileButton_Click(object sender, EventArgs e)
 {
     myCPU.resetCPU();
     myMem.clear();
     using (var ofd = new OpenFileDialog())
     {
         if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             try
             {
                 var ipe = new IPE(ofd.FileName);
                 ipe.mem = myMem;
                 myCPU.mem = myMem;
                 ipe.ParseFile();
             }
             catch (Exception err)
             {
            
             }
         }
     }
     myCPU.branchPredictionTable = new CPU.branchPredictionStruct[100];
     for (int i = 0; i < myCPU.branchPredictionTable.Length; i++)
     {
         CPU.branchPredictionStruct initial = new CPU.branchPredictionStruct();
         initial.branchPC = -1;
         myCPU.branchPredictionTable[i] = initial;
     }
     setInitialCPUValuesToView();
 }
Exemplo n.º 4
0
 private void loadFileButton_Click(object sender, EventArgs e)
 {
     using (var ofd = new OpenFileDialog())
     {
         if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             try
             {
                 resetGUI();
                 string fileName = Path.GetFileNameWithoutExtension(ofd.FileName);
                 this.fileNameLabel.Text = fileName + ".s";
                 var ipe = new IPE(ofd.FileName);
                 List<string> assemblyLines = ipe.ParseFile();
                 if (assemblyLines.Count == 0)
                 {
                     return;
                 }
                 short[] binaryLines = ipe.AssemblytoBinary(assemblyLines);
                 string tempFileName = Path.GetDirectoryName(ofd.FileName) + "\\" + fileName + ".out";
                 Debug.WriteLine("\nOutput to file: " + tempFileName);
                 ipe.WriteBinarytoFile(binaryLines, tempFileName);//Write out the binary instructions to a file
                 binaryLines = ipe.readBinaryFromFile(tempFileName);//Read in the binary and load to memory
                 Memory.setBinaryInstructions(binaryLines.ToList());//Load the binary we just read from file into Memory
                 currentInstructionLabel.Text = Memory.getAssemblyInstructions().ElementAt(0);
                 this.setPipelineValuesToView();//not sure if this is needed
                 totalInstructionCountLabel.Text = (Memory.getAssemblyInstructions().Count).ToString();
                 instructionCount = 1;
                 currInstructionCountLabel.Text = (this.myCPU.PC+1).ToString();
             }
             catch (Exception err)
             {
                 // show a dialog with error     
                 MessageBox.Show(err.Message);
                 resetGUI();
             }
         }
     }
 }