コード例 #1
0
        private void UpdateTextboxes()
        {
            try
            {
                textBoxBytes.Clear();
                textBoxLabels.Clear();
                textBoxVariables.Clear();

                var asmSource = AssemblerClass.SourceToMachineCode(textBoxAssembly.Text);

                textBoxBytes.Text = asmSource.BytesAsText;

                foreach (var label in asmSource.Labels)
                {
                    var key = (label.Key.Length > 24) ? label.Key.Substring(0, 21) + "..." : label.Key.PadRight(24);

                    textBoxLabels.Text +=
                        string.Format("{0} {1:x4}", key, label.Value) +
                        Environment.NewLine;
                }

                foreach (var variable in asmSource.Variables)
                {
                    var key = (variable.Key.Length > 24) ? variable.Key.Substring(0, 21) + "..." : variable.Key.PadRight(24);

                    textBoxVariables.Text +=
                        string.Format("{0} {1:x4}", key, variable.Value) +
                        Environment.NewLine;
                }

                LblStatus.ForeColor = Color.DarkGreen;
                LblStatus.Text      = "Valid";
            }
            catch (Exception ex)
            {
                LblStatus.ForeColor = Color.Red;
                LblStatus.Text      = "Invalid. " + ex.Message;
            }
        }
コード例 #2
0
        // argv[0] -> input program
        // argv[1] -> output machine code
        static void Main(String[] args)
        {
            // main assembler class

            if (args.Length == 2)
            {
                AssemblerClass assembler = new AssemblerClass(args);
                var            a         = assembler.readCodeAndCheck();
                if (a.Count > 0)
                {
                    foreach (var i in a)
                    {
                        Console.WriteLine(i);
                    }
                    var b = assembler.createMachineCode();

                    foreach (var i in b)
                    {
                        Console.WriteLine(i);
                    }
                }
                else
                {
                    Console.WriteLine("Assembled with errors: ");
                    foreach (var i in assembler.getErrorList())
                    {
                        Console.WriteLine(i);
                    }
                }
                // end assembling
            }
            else
            {
                // show error
                Console.Out.Write("error: <assembly-code-file> <machine-code-file>\n");
                Console.ReadKey();
            }
        }
コード例 #3
0
        public FormMain()
        {
            InitializeComponent();

            this.Text = string.Format("Assembler for JACA Homebrew Computer v.{0}", Constants.VERSION);

            // Command line for Notepad++:
            // "C:\Users\albs_\Source\Repos\jaca\2nd gen - 8 bit cpu\Assembler\Assembler\bin\Debug\Assembler.exe" "$(FULL_CURRENT_PATH)" "C:\Users\albs_\Source\Repos\jaca\2nd gen - 8 bit cpu\compiled.bin"

            string[] args = Environment.GetCommandLineArgs();

            if (args.Length == 3)
            {
                try
                {
                    var sourceFullPath  = args[1];
                    var destinyFullPath = args[2];

                    var source = File.OpenText(sourceFullPath).ReadToEnd();

                    var asmSource = AssemblerClass.SourceToMachineCode(source);

                    SaveToLogisimBinFile(asmSource.BytesAsText, destinyFullPath);

                    textBoxAssembly.Text = source;
                    UpdateTextboxes();

                    MessageBox.Show("Source compiled successfully",
                                    "Information");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while compiling. " + ex.Message,
                                    "Error");
                }
            }
        }