private void AssembleButton_Click(object sender, EventArgs e)
        {
            if (SourceFilePathTextBox.Text == string.Empty)
            {
                SaveFileDialog.Filter   = "asm file (*.asm)|*.asm";
                SaveFileDialog.FileName = "";
                if (SaveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    sourcepath = SaveFileDialog.FileName;
                    SourceFilePathTextBox.Text = sourcepath;
                }
            }

            StreamWriter sw = new StreamWriter(sourcepath, false);

            for (int i = 0; i < SourceRichTextBox.Lines.Length; i++)
            {
                sw.WriteLine(SourceRichTextBox.Lines[i]);
            }
            sw.Close();
            OutputRichTextBox.Text = "";

            int[] intarray = new int [1];
            MIPS246.Core.Assembler.Assembler assembler = new MIPS246.Core.Assembler.Assembler(sourcepath, outputpath);
            if (assembler.DoAssemble() == true)
            {
                for (int i = 0; i < assembler.CodeList.Count; i++)
                {
                    assembler.CodeList[i].Machine_Code.CopyTo(intarray, 0);
                    if (HEXRadioButton.Checked == false)
                    {
                        OutputRichTextBox.Text += "0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t" + string.Format("{0:x}", Convert.ToString(intarray[0], 2)).PadLeft(32, '0') + "\r\n";
                    }
                    else
                    {
                        OutputRichTextBox.Text += "0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t" + "0x" + string.Format("{0:x}", Convert.ToString(intarray[0], 16)).PadLeft(8, '0') + "\r\n";
                    }
                }

                if (isOutputFile == true)
                {
                    assembler.Output(isOutputCOE, outputpath, false);
                }
            }
            else
            {
                OutputRichTextBox.Text = assembler.Error.ToString();
            }
        }
        private void AssembleButton_Click(object sender, EventArgs e)
        {
            if (SourceFilePathTextBox.Text == string.Empty)
            {
                SaveFileDialog.Filter = "asm file (*.asm)|*.asm";
                SaveFileDialog.FileName = "";
                if (SaveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    sourcepath = SaveFileDialog.FileName;
                    SourceFilePathTextBox.Text = sourcepath;
                }
            }

            StreamWriter sw = new StreamWriter(sourcepath, false);
            for (int i = 0; i < SourceRichTextBox.Lines.Length; i++)
            {
                sw.WriteLine(SourceRichTextBox.Lines[i]);
            }
            sw.Close();
            OutputRichTextBox.Text = "";

            int[] intarray=new int [1];
            MIPS246.Core.Assembler.Assembler assembler = new MIPS246.Core.Assembler.Assembler(sourcepath, outputpath);
            if (assembler.DoAssemble() == true)
            {
                for (int i = 0; i < assembler.CodeList.Count; i++)
                {
                    assembler.CodeList[i].Machine_Code.CopyTo(intarray,0);
                    if (HEXRadioButton.Checked == false)
                    {
                        OutputRichTextBox.Text += "0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t"  + string.Format("{0:x}", Convert.ToString(intarray[0], 2)).PadLeft(32, '0') + "\r\n";
                    }
                    else
                    {
                        OutputRichTextBox.Text += "0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t" + "0x" + string.Format("{0:x}", Convert.ToString(intarray[0], 16)).PadLeft(8, '0') + "\r\n";
                    }
                }

                if (isOutputFile == true)
                {
                    assembler.Output(isOutputCOE, outputpath, false);
                }
            }
            else
            {
                OutputRichTextBox.Text = assembler.Error.ToString();
            }
        }
    public static string Assemble(string sourceCode, string displayFormat, string hasAddress)
    {
        string output = "";

        MIPS246.Core.Assembler.Assembler assembler = new MIPS246.Core.Assembler.Assembler(sourceCode);
        if (assembler.DoAssemble() == true)
        {
            bool[] boolArray = new bool[32];
            for (int i = 0; i < assembler.CodeList.Count; i++)
            {
                assembler.CodeList[i].Machine_Code.CopyTo(boolArray, 0);
                if (displayFormat == "BIN")
                {
                    if (hasAddress == "checked")
                    {
                        output += "0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t";
                    }
                    for (int j = 0; j < 32; j++)
                    {
                        if (boolArray[j] == true)
                        {
                            output += "1";
                        }
                        else
                        {
                            output += "0";
                        }
                    }
                    output += "\n";
                }
                else
                {
                    if (hasAddress == "checked")
                    {
                        output += "0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t";
                    }
                    output += FormatHex(boolArray);
                    output += "\n";
                }
            }
        }
        else
        {
            output = assembler.Error.ToString();
        }
        return(output);
    }
 public static string Assemble(string sourceCode, string displayFormat,string hasAddress)
 {
     string output="";
     MIPS246.Core.Assembler.Assembler assembler = new MIPS246.Core.Assembler.Assembler(sourceCode);
     if (assembler.DoAssemble() == true)
     {
         bool[] boolArray = new bool[32];
         for (int i = 0; i < assembler.CodeList.Count; i++)
         {
             assembler.CodeList[i].Machine_Code.CopyTo(boolArray,0);
             if (displayFormat == "BIN")
             {
                 if (hasAddress == "checked")
                 {
                     output+="0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t";
                 }
                 for (int j = 0; j < 32; j++)
                 {
                     if (boolArray[j] == true)
                     {
                         output += "1";
                     }
                     else
                     {
                         output += "0";
                     }
                 }
                 output += "\n";
             }
             else
             {
                 if (hasAddress == "checked")
                 {
                     output+="0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t";
                 }
                 output+=FormatHex(boolArray);
                 output += "\n";
             }
         }
     }
     else
     {
         output= assembler.Error.ToString();
     }
     return output;
 }
    public static string SaveTargetCode(string sourceCode, string displayFormat, string outputFormat)
    {
        string output = "";
        string fileName = Guid.NewGuid().ToString();
        bool isHEX;
        MIPS246.Core.Assembler.Assembler assembler = new MIPS246.Core.Assembler.Assembler(sourceCode);
        if(outputFormat=="BIN")
        {
            isHEX=false;
        }
        else
        {
            isHEX=true;
        }

        if (assembler.DoAssemble() == true)
        {

            if (outputFormat == "TXT")
            {
                fileName += ".txt";
                assembler.Output(false, HttpContext.Current.Server.MapPath("~") + "/AssemblerOutput/" + fileName, isHEX);
            }
            else
            {
                fileName += ".coe";
                assembler.Output(true, HttpContext.Current.Server.MapPath("~") + "/AssemblerOutput/" + fileName, isHEX);
            }
        }
        else
        {
            output = assembler.Error.ToString();
        }

        return fileName;
    }
    public static string SaveTargetCode(string sourceCode, string displayFormat, string outputFormat)
    {
        string output   = "";
        string fileName = Guid.NewGuid().ToString();
        bool   isHEX;

        MIPS246.Core.Assembler.Assembler assembler = new MIPS246.Core.Assembler.Assembler(sourceCode);
        if (outputFormat == "BIN")
        {
            isHEX = false;
        }
        else
        {
            isHEX = true;
        }

        if (assembler.DoAssemble() == true)
        {
            if (outputFormat == "TXT")
            {
                fileName += ".txt";
                assembler.Output(false, HttpContext.Current.Server.MapPath("~") + "/AssemblerOutput/" + fileName, isHEX);
            }
            else
            {
                fileName += ".coe";
                assembler.Output(true, HttpContext.Current.Server.MapPath("~") + "/AssemblerOutput/" + fileName, isHEX);
            }
        }
        else
        {
            output = assembler.Error.ToString();
        }

        return(fileName);
    }
示例#7
0
        public bool doAssembler(string inputPath, string outputPath, bool reset)
        {
            assembler = new MIPS246.Core.Assembler.Assembler(inputPath, outputPath);
            if (reset)
            {
                Form1.Reset();
            }
            else
            {
                RunTimeCode.Clear();
            }
            if (assembler.DoAssemble() == true)
            {
                List <String[]> sourceList = assembler.SourceList;
                lineTable = assembler.Linetable;
                List <Instruction> codeList = assembler.CodeList;

                if (MipsSimulator.Program.mode != 1)
                {
                    RunTimeCode.CodeTInitial();
                }

                for (int i = 0; i < codeList.Count; i++)
                {
                    CodeType codeType    = convertToCodeType(codeList[i].Mnemonic.ToString());
                    string   machineCode = convertToMachineCode(codeList[i].Machine_Code);

                    int    p       = (int)lineTable[i];
                    string codeStr = sourceList[p][0] + " ";
                    for (int s = 1; s < sourceList[p].Count(); s++)
                    {
                        codeStr += sourceList[p][s] + ",";
                    }
                    if (codeStr.Substring(codeStr.Length - 1, 1) == ",")
                    {
                        codeStr = codeStr.Substring(0, codeStr.Length - 1);
                    }
                    Code code = new Assembler.Code(codeType, null, codeStr, machineCode);
                    code.index   = i;
                    code.address = codeList[i].Address;
                    RunTimeCode.codeList.Add(code);
                }

                for (int i = 0; i < sourceList.Count; i++)
                {
                    string codeStr = sourceList[i][0] + " ";
                    for (int s = 1; s < sourceList[i].Count(); s++)
                    {
                        codeStr += sourceList[i][s] + ",";
                    }
                    if (codeStr.Substring(codeStr.Length - 1, 1) == ",")
                    {
                        codeStr = codeStr.Substring(0, codeStr.Length - 1);
                    }
                    string machineCode = "";
                    int    j           = 0;
                    for (j = 0; j < lineTable.Count; j++)
                    {
                        if ((int)lineTable[j] == i)
                        {
                            break;
                        }
                    }
                    if (j != lineTable.Count)
                    {
                        machineCode = RunTimeCode.codeList[j].machineCode;
                        Int32 tmp = (Int32)CommonTool.StrToNum(TypeCode.Int32, machineCode, 2);
                        machineCode = "0x" + tmp.ToString("X8");
                    }
                    Code code = new Assembler.Code(CodeType.NOP, null, codeStr, machineCode);
                    code.index   = i;
                    code.address = codeList[j].Address;
                    RunTimeCode.Add(code);
                }
            }
            else
            {
                MipsSimulator.Tools.FileControl.WriteFile(outputPath, assembler.Error.ToString());
                return(false);
            }
            return(true);
        }
示例#8
0
        public bool doAssembler(string inputPath, string outputPath,bool reset)
        {
            assembler = new MIPS246.Core.Assembler.Assembler(inputPath, outputPath);
            if (reset)
            {
                Form1.Reset();
            }
            else
            {
                RunTimeCode.Clear();
            }
            if (assembler.DoAssemble() == true)
            {
                List<String> sourceList = assembler.RawSource;
                lineTable = assembler.Linetable;
                List<Instruction> codeList = assembler.CodeList;

                if (MipsSimulator.Program.mode != 1)
                {
                    RunTimeCode.CodeTInitial();
                }

                for (int i = 0; i < codeList.Count; i++)
                {
                    CodeType codeType = convertToCodeType(codeList[i].Mnemonic.ToString());
                    string machineCode = convertToMachineCode(codeList[i].Machine_Code);

                    int p = (int)lineTable[i];
                    string codeStr = sourceList[p];

                    Code code = new Assembler.Code(codeType, null, codeStr, machineCode);
                    code.index = i;
                    code.address = codeList[i].Address;
                    RunTimeCode.codeList.Add(code);
                }

                for (int i = 0; i < sourceList.Count; i++)
                {
                    string codeStr = sourceList[i];

                    string machineCode = "";
                    int j = 0;
                    for (j = 0; j < lineTable.Count; j++)
                    {
                        if ((int)lineTable[j] == i)
                        {
                            break;
                        }
                    }
                    if (j != lineTable.Count)
                    {
                        machineCode = RunTimeCode.codeList[j].machineCode;
                        Int32 tmp = (Int32)CommonTool.StrToNum(TypeCode.Int32, machineCode, 2);
                        machineCode = "0x" + tmp.ToString("X8");
                        Code code = new Assembler.Code(CodeType.NOP, null, codeStr, machineCode);
                        code.index = i;
                        code.address = codeList[j].Address;
                        RunTimeCode.Add(code);
                    }
                    else
                    {
                        Code code = new Assembler.Code(CodeType.NOP, null, codeStr, machineCode);
                        code.index = i;
                        code.address =-1;
                        RunTimeCode.Add(code);
                    }

                }

            }
            else
            {
                MipsSimulator.Tools.FileControl.WriteFile(outputPath, assembler.Error.ToString());
                return false;
            }
            return true;
        }
        private void AssembleButton_Click(object sender, EventArgs e)
        {
            if (SourceFilePathTextBox.Text == string.Empty)
            {
                SaveFileDialog.Filter = "asm file (*.asm)|*.asm";
                SaveFileDialog.FileName = "";
                if (SaveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    sourcepath = SaveFileDialog.FileName;
                    SourceFilePathTextBox.Text = sourcepath;
                }
                else
                {
                    sourcepath = @"c:\windows\temp\temp.asm";
                    SourceFilePathTextBox.Text = sourcepath;
                }
            }

            StreamWriter sw = new StreamWriter(sourcepath, false);
            for (int i = 0; i < SourceRichTextBox.Lines.Length; i++)
            {
                sw.WriteLine(SourceRichTextBox.Lines[i]);
            }
            sw.Close();
            OutputRichTextBox.Text = "";

            bool[] boolArray = new bool[32];
            outputpath = OutputPathTextBox.Text;
            assembler = new MIPS246.Core.Assembler.Assembler(sourcepath, outputpath);
            if (assembler.DoAssemble() == true)
            {
                for (int i = 0; i < assembler.CodeList.Count; i++)
                {
                    assembler.CodeList[i].Machine_Code.CopyTo(boolArray,0);
                    if (HEXRadioButton.Checked == false)
                    {
                        OutputRichTextBox.Text += "0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t";
                        for (int j = 0; j < 32; j++)
                        {
                            if (boolArray[j] == true)
                            {
                                OutputRichTextBox.Text += "1";
                            }
                            else
                            {
                                OutputRichTextBox.Text += "0";
                            }
                        }
                        OutputRichTextBox.Text += "\r\n";
                    }
                    else
                    {
                        OutputRichTextBox.Text += "0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t";
                        OutputRichTextBox.Text += FormatHex(boolArray);
                        OutputRichTextBox.Text += "\r\n";
                    }
                }

                if (isOutputFile == true)
                {
                    assembler.Output(isOutputCOE, outputpath, HEXRadioButton.Checked);
                }
            }
            else
            {
                OutputRichTextBox.Text = assembler.Error.ToString();
            }
        }
示例#10
0
        private void AssembleButton_Click(object sender, EventArgs e)
        {
            if (SourceFilePathTextBox.Text == string.Empty)
            {
                SaveFileDialog.Filter   = "asm file (*.asm)|*.asm";
                SaveFileDialog.FileName = "";
                if (SaveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    sourcepath = SaveFileDialog.FileName;
                    SourceFilePathTextBox.Text = sourcepath;
                }
                else
                {
                    sourcepath = @"c:\windows\temp\temp.asm";
                    SourceFilePathTextBox.Text = sourcepath;
                }
            }

            StreamWriter sw = new StreamWriter(sourcepath, false);

            for (int i = 0; i < SourceRichTextBox.Lines.Length; i++)
            {
                sw.WriteLine(SourceRichTextBox.Lines[i]);
            }
            sw.Close();
            OutputRichTextBox.Text = "";

            bool[] boolArray = new bool[32];
            outputpath = OutputPathTextBox.Text;
            assembler  = new MIPS246.Core.Assembler.Assembler(sourcepath, outputpath);
            if (assembler.DoAssemble() == true)
            {
                for (int i = 0; i < assembler.CodeList.Count; i++)
                {
                    assembler.CodeList[i].Machine_Code.CopyTo(boolArray, 0);
                    if (HEXRadioButton.Checked == false)
                    {
                        OutputRichTextBox.Text += "0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t";
                        for (int j = 0; j < 32; j++)
                        {
                            if (boolArray[j] == true)
                            {
                                OutputRichTextBox.Text += "1";
                            }
                            else
                            {
                                OutputRichTextBox.Text += "0";
                            }
                        }
                        OutputRichTextBox.Text += "\r\n";
                    }
                    else
                    {
                        OutputRichTextBox.Text += "0x" + String.Format("{0:X8}", assembler.CodeList[i].Address) + ":\t";
                        OutputRichTextBox.Text += FormatHex(boolArray);
                        OutputRichTextBox.Text += "\r\n";
                    }
                }

                if (isOutputFile == true)
                {
                    assembler.Output(isOutputCOE, outputpath, HEXRadioButton.Checked);
                }
            }
            else
            {
                OutputRichTextBox.Text = assembler.Error.ToString();
            }
        }