Exemplo n.º 1
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="mm">Memory</param>
 /// <param name="w">UVSim controller</param>
 public Compilator(MemoryManager mm, IUVSimController w)
 {
     memory     = mm;
     window     = w;
     isVariable = new Dictionary <int, string>();
     isNumber   = new List <int>();
     charIndex  = 97;
 }
Exemplo n.º 2
0
        // Default constructor.
        public VirtualMachine(MemoryManager m, int numPrograms, IUVSimController w)
        {
            memory        = m;
            window        = w;
            currentThread = 0;

            // Creating virtual threads
            threads = new Thread[numPrograms];
            for (int i = 0; i < numPrograms; i++)
            {
                Thread thread = new Thread(i);
                threads[i] = thread;
            }
        }
Exemplo n.º 3
0
        public static void Error(this IUVSimController window, string error)
        {
            RichEditControl console = window.Console;

            console.Dispatcher.Invoke(() =>
            {
                console.BeginUpdate();
                var paragraph = console.Document.Paragraphs.Append();
                console.Document.InsertText(paragraph.Range.Start, $"{error}.\r\n");
                //var charProperties = console.Document.BeginUpdateCharacters(paragraph.Range);
                //charProperties.ForeColor = System.Drawing.Color.Red;
                //console.Document.EndUpdateCharacters(charProperties);
                console.EndUpdate();
            });
        }
Exemplo n.º 4
0
        public static int Read(this IUVSimController window)
        {
            window.Input      = string.Empty;
            window.ResetEvent = new ManualResetEvent(false);
            window.Console.Dispatcher.Invoke(() =>
            {
                window.Console.Focus();
            });
            window.ResetEvent.WaitOne();
            window.ResetEvent.Close();
            window.ResetEvent = null;
            int result = 0;

            int.TryParse(window.Input, out result);
            if ((result < Accumilator.MIN_NUMBER) || (result > Accumilator.MAX_NUMBER))
            {
                throw new ApplicationException("Overflow error: The value is beyond range.");
            }
            return(result);
        }
Exemplo n.º 5
0
 public BasicMLIndirect(IUVSimController w, MemoryManager m) : base(w, m)
 {
 }
Exemplo n.º 6
0
 public BasicML(IUVSimController w, MemoryManager m)
 {
     window = w;
     memory = m;
     alu    = new ALU();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Execute new instruction in the thread
        /// </summary>
        /// <param name="memory">System memory</param>
        /// <param name="window">UVSim Controller</param>
        public void Execute(MemoryManager memory, IUVSimController window)
        {
            // Check if thread was terminated
            if (Terminated)
            {
                return;
            }

            // Create executioners
            BasicML     directExecution   = new BasicMLDirect(window, memory);
            BasicML     indirectExecution = new BasicMLIndirect(window, memory);
            BasicMLMath directMath        = new BasicMLMathDirect(window, memory);
            BasicMLMath indirectMath      = new BasicMLMathIndirect(window, memory);

            // Retrieve pc value from memory
            int pc = memory[THREAD_OFFSET * ThreadNumber + (THREAD_OFFSET - 1)];

            pc = THREAD_OFFSET * ThreadNumber + pc;

            //Retrieve register from memory
            int memoryLocation = THREAD_OFFSET * ThreadNumber + (THREAD_OFFSET - 3);

            Accumilator.Instance.Value = directExecution.ComposeDWORD(ref memoryLocation);

            try
            {
                int opCode;

                // Get the opCode
                opCode = memory[pc] / 100;

                // Switch statment to execute the targeted instruction based on the opCode.
                switch (opCode)
                {
                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Josh Cooley

                // READ
                case 10:
                    window.Console.Write($"[Thread #{ThreadNumber}] ");
                    directExecution.Read(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Josh Cooley

                // WRITE
                case 11:
                    window.Console.Write($"[Thread #{ThreadNumber}] ");
                    directExecution.Write(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Josh Cooley

                // READ - INDIRECT
                case 12:
                    window.Console.Write($"[Thread #{ThreadNumber}] ");
                    indirectExecution.Read(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Josh Cooley

                // WRITE - INDIRECT
                case 13:
                    window.Console.Write($"[Thread #{ThreadNumber}] ");
                    indirectExecution.Write(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Josh Cooley

                // LOAD
                case 20:

                    directExecution.Load(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Nikita Pestin

                // STORE
                case 21:

                    directExecution.Store(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Nikita Pestin

                // LOAD - INDIRECT
                case 22:

                    indirectExecution.Load(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Nikita Pestin

                // STORE - INDIRECT
                case 23:

                    indirectExecution.Load(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Nikita Pestin

                // ADD
                case 30:

                    directMath.Add(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Nikita Pestin

                // SUBTRACT
                case 31:

                    directMath.Subtract(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Caleb Hansen

                // DIVIDE
                case 32:

                    directMath.Divide(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Caleb Hansen

                // MULTIPLY
                case 33:

                    directMath.Multiply(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Nikita Pestin

                // ADD - INDIRECT
                case 34:

                    indirectMath.Add(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Nikita Pestin

                // SUBTRACT - INDIRECT
                case 35:

                    indirectMath.Subtract(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Nikita Pestin

                // DIVIDE - INDIRECT
                case 36:

                    indirectMath.Divide(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Nikita Pestin

                // MULTIPLY - INDIRECT
                case 37:

                    indirectMath.Multiply(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Caleb Hansen

                // BRANCH
                case 40:

                    directExecution.Branch(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Ali Alabdlmohsen

                // BRANCHNEG
                case 41:

                    directExecution.BranchNeg(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Ali Alabdlmohsen

                // BRANCHZERO
                case 42:

                    directExecution.BranchZero(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Ali Alabdlmohsen

                // HALT
                case 43:

                    // End the execution.
                    window.Console.WriteLine("---------------------------------------------");
                    terminated = true;
                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Caleb Hansen

                // BRANCH - Josh Cooley
                case 44:

                    indirectExecution.Branch(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Ali Alabdlmohsen

                // BRANCHNEG - INDIRECT
                case 45:

                    indirectExecution.BranchNeg(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Ali Alabdlmohsen

                // BRANCHZERO - INDIRECT
                case 46:

                    indirectExecution.BranchZero(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Ali Alabdlmohsen

                // REMINDER
                case 50:

                    directMath.Reminder(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Ali Alabdlmohsen

                // EXPONENTIATION
                case 51:

                    directMath.Exponential(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Ali Alabdlmohsen

                // REMINDER - INDIRECT
                case 52:

                    indirectMath.Reminder(ref pc);

                    break;

                //-----------------------------------------------------------------------------------------------------------------------
                // Coded by: Ali Alabdlmohsen

                // EXPONENTIATION - INDIRECT
                case 53:

                    indirectMath.Exponential(ref pc);

                    break;

                // Defult.
                default:

                    // Increment the program counter.
                    pc++;

                    break;
                }
            }
            catch (Exception ex)
            {
                window.Console.Write($"[Thread #{ThreadNumber}] ");
                window.Error(ex.Message);
                terminated = true;
            }

            // Check termination
            if ((pc % THREAD_OFFSET) >= (THREAD_OFFSET - 3))
            {
                terminated = true;
            }

            // Save program counter and accumulator to memory
            pc %= THREAD_OFFSET;
            memory[THREAD_OFFSET * ThreadNumber + (THREAD_OFFSET - 1)] = pc;
            directExecution.SaveDWORD(THREAD_OFFSET * ThreadNumber + (THREAD_OFFSET - 3), Accumilator.Instance.Value);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Window constructor
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            controller = new UVSimController(this);
        }
Exemplo n.º 9
0
 public Assembler(IUVSimController window, MemoryManager mm)
 {
     this.window = window;
     memory      = mm;
 }