Example #1
0
 //Jaren Flaker
 public static void BranchZero(this UVSimModel uvSim, string operand)
 {
     if (uvSim.Accumulator == 0)
     {
         uvSim.ProgramCounter = int.Parse(operand);
     }
 }
Example #2
0
        //public void AcceptUserProgram()
        //{

        //    int memoryLocation = 0;
        //    string response;

        //    do // User is still entering commands
        //    {
        //        //Keep accepting commands
        //        Console.Write(memoryLocation + " ? ");
        //        response = Console.ReadLine();

        //        string operation = response.Substring(0, 2);
        //        string operand = response.Substring(2, 2);

        //        memory.Add(new WordModel { MemoryLocation = memoryLocation++, Operation = operation, Operand = operand });
        //    } while (response != "9999");

        //    foreach (var word in memory)
        //    {
        //        RunCommand(word.Operation, word.Operand);
        //        pc++;
        //    }
        //}

        public static void RunProgram(this UVSimModel uvSim, List <string> program)
        {
            foreach (var instruction in program)
            {
                uvSim.RunCommand(instruction);
            }
        }
 public static void BranchZero(this UVSimModel uvSim, string operand)
 {
     //if (accumulator == 0)
     //{
     //    //pc = operand - 1;
     //}
 }
        // Cameron Prestera
        public static void Write(this UVSimModel uvSim, string operand)
        {
            //Jaren Flaker
            string output = "Output: " + uvSim.Memory[int.Parse(operand)];

            uvSim.OutputTextblock.Text += output;
        }
Example #5
0
 //Debugging Operations
 public static void MemDump(this UVSimModel uvSim)
 {
     //Console.WriteLine("\nAccumilator: {0:d2}\nOpcode: {1:d2}\nOperand: {2:d2}\n\nMemory Dump: ", accumulator, opcode, operand);
     //for (int i = 0; i < MEM_SIZE; i++)
     //{
     //    Console.WriteLine("{0:d2}: {1}", i, memory[i]);
     //}
 }
Example #6
0
        //I/O Operations
        public static void Read(this UVSimModel uvSim, string operand)
        {
            string input = Prompt.ShowDialog("Enter an integer:", "Read Operation");

            uvSim.Memory[int.Parse(operand)] = input;

            // TODO - Output "Enter an integer: {input}" to the output textblock
            uvSim.Output += "Enter an integer: " + input + "\n";
        }
        // Cameron Prestera
        public static void Read(this UVSimModel uvSim, string operand)
        {
            string input = Prompt.ShowDialog("Enter an integer:", "Read Operation");

            input = input.PadLeft(4, '0');

            uvSim.Memory[int.Parse(operand)] = input;

            uvSim.OutputTextblock.Text += "Enter an integer: " + input + "\n";
        }
Example #8
0
        public static string GetMemoryDump(this UVSimModel uvSim)
        {
            string memory = "";

            foreach (var word in uvSim.Memory)
            {
                memory += word + "\n";
            }

            return(memory);
        }
        // Cameron Prestera
        public static void Subtract(this UVSimModel uvSim, string operand)
        {
            int currentAccumulator = uvSim.Accumulator;
            int theOperand = int.Parse(operand);

            theOperand = SubtractionHelper(~theOperand, 1);

            currentAccumulator = SubtractionHelper(currentAccumulator, theOperand);

            uvSim.Accumulator -= int.Parse(uvSim.Memory[int.Parse(operand)]);
        }
Example #10
0
        public static void DisplayGreeting(this UVSimModel uvSim)
        {
            string greeting = "";

            greeting += "Welcome to JCB's UV Simulator!\n";
            greeting += "Please enter instructions one data-word at a time.\n";
            greeting += "Data words are positve or negative 4 digit strings.\n";
            greeting += "When you are finished, enter -99999 to stop and run program.\n";
            greeting += "Please enter commands:\n";

            MessageBox.Show(greeting);
        }
        //ALU
        public static void Add(this UVSimModel uvSim, string operand)
        {
            /*accumulator += int.Parse(memory[operand]);*/
            // uvSim.Add()'

            //string o1 = uvSim.Memory[int.Parse(operand)].Operation;
            //string o2 = uvSim.Memory[int.Parse(operand)].Operand;

            //uvSim.Accumulator = new WordModel { Operation = o1, Operand = o2 };

            uvSim.Accumulator += int.Parse(uvSim.Memory[int.Parse(operand)]);
        }
Example #12
0
        // Ben Thornhill
        public static void DisplayGreeting(this UVSimModel uvSim)
        {
            string greeting = "";

            greeting += "Welcome to JCB's UV Simulator!\n";
            greeting += "---------------------------------------------------------\n\n";

            greeting += "Select Command from the operation list and enter memory location you would like to use.\n\n";
            greeting += "If you would like to run more than one simmulator at a time you can use the launch button in the previous window.\n\n";

            uvSim.OutputTextblock.Text += greeting;
        }
 // Cameron Prestera
 public static void Add(this UVSimModel uvSim, string operand)
 {
     int currentAccumulator = uvSim.Accumulator;
     int theOperand = int.Parse(operand);
     int Carry;
     while (theOperand != 0)
     {
         Carry = currentAccumulator & theOperand;
         currentAccumulator ^= theOperand;
         theOperand = Carry << 1;
     }
     uvSim.Accumulator += currentAccumulator; //int.Parse(uvSim.Memory[int.Parse(operand)]);
 }
Example #14
0
        // Cameron Prestera
        public static void DisplayMemory(this UVSimModel uvSim)
        {
            string memory         = "";
            int    memoryLocation = 0;

            foreach (var word in uvSim.Memory)
            {
                memory += memoryLocation.ToString().PadLeft(3, '0') + " | " + word + "\n";
                memoryLocation++;
            }

            uvSim.MemoryTextblock.Text = memory;
        }
Example #15
0
        // Jaren Flaker
        public static List <OperationModel> GetAvailableOperations(this UVSimModel uvSim)
        {
            List <OperationModel> output = new List <OperationModel>();

            output.Add(new OperationModel {
                Name = "Read", OpCode = "10"
            });
            output.Add(new OperationModel {
                Name = "Write", OpCode = "11"
            });
            output.Add(new OperationModel {
                Name = "Load", OpCode = "20"
            });
            output.Add(new OperationModel {
                Name = "Store", OpCode = "21"
            });
            output.Add(new OperationModel {
                Name = "Add", OpCode = "30"
            });
            output.Add(new OperationModel {
                Name = "Subtract", OpCode = "31"
            });
            output.Add(new OperationModel {
                Name = "Divide", OpCode = "32"
            });
            output.Add(new OperationModel {
                Name = "Multiply", OpCode = "33"
            });
            output.Add(new OperationModel {
                Name = "Remainder", OpCode = "34"
            });
            output.Add(new OperationModel {
                Name = "Exponent", OpCode = "35"
            });
            output.Add(new OperationModel {
                Name = "Branch", OpCode = "40"
            });
            output.Add(new OperationModel {
                Name = "BranchNeg", OpCode = "41"
            });
            output.Add(new OperationModel {
                Name = "BranchZero", OpCode = "42"
            });
            output.Add(new OperationModel {
                Name = "Halt", OpCode = "43"
            });

            return(output);
        }
Example #16
0
        public UVSimDashboard(int memorySize)
        {
            InitializeComponent();

            PopulateOperationsListbox();

            uvSim = new UVSimModel(memorySize);
            uvSim.OutputTextblock = outputTextblock;
            uvSim.MemoryTextblock = memoryTextblock;

            RefreshMemoryListbox();


            uvSim.DisplayGreeting();
        }
Example #17
0
 private static void RunCommand(this UVSimModel uvSim, string instruction)
 {
     string operation = instruction.Substring(0, 2);
     string operand   = instruction.Substring(2, 2);
     //switch (operation)
     //{
     //    case "10":
     //        Read(operand);
     //        break;
     //    case "11":
     //        Write(operand);
     //        break;
     //    case "20":
     //        Load(operand);
     //        break;
     //    case "21":
     //        Store(operand);
     //        break;
     //    case "30":
     //        Add(operand);
     //        break;
     //    case "31":
     //        Subtract(operand);
     //        break;
     //    case "32":
     //        Divide(operand);
     //        break;
     //    case "33":
     //        Multiply(operand);
     //        break;
     //    case "40":
     //        Branch(operand);
     //        break;
     //    case "41":
     //        BranchNeg(operand);
     //        break;
     //    case "42":
     //        BranchZero(operand);
     //        break;
     //    case "43":
     //        Halt();
     //        break;
     //}
 }
Example #18
0
        // Ben Thornhill
        public static void RunProgram(this UVSimModel uvSim)
        {
            //Changed so program will run untill a halt command or reaches end of memory
            while (uvSim.ProgramCounter != -666 && uvSim.ProgramCounter < uvSim.MemorySize)
            {
                string firstWord       = uvSim.Memory[uvSim.ProgramCounter];
                string secondWord      = uvSim.Memory[uvSim.ProgramCounter + 1];
                string fullInstruction = firstWord + secondWord;

                try
                {
                    uvSim.RunCommand(fullInstruction);
                }
                catch
                {
                    string firstWordWithoutBreakpoint = firstWord.Substring(0, 2) + "00";
                    uvSim.Memory[uvSim.ProgramCounter] = firstWordWithoutBreakpoint;
                    throw;
                }

                uvSim.ProgramCounter += 2;
            }
        }
Example #19
0
 public static void Write(this UVSimModel uvSim, string operand)
 {
     //Console.WriteLine("Contents of location {0}: {1}", operand, memory[int.Parse(operand)]);
     uvSim.Output += "Contentis of location " + operand + " is " + uvSim.Memory[int.Parse(operand)];
 }
Example #20
0
 public static void Store(this UVSimModel uvSim, string operand)
 {
     uvSim.Memory[int.Parse(operand)] = uvSim.Accumulator.ToString();
 }
Example #21
0
 // Cameron Prestera
 public static void DisplayRegisterStats(this UVSimModel uvSim)
 {
     //Jaren Flaker
     uvSim.OutputTextblock.Text += $"\nAccumilator: {uvSim.Accumulator}\n";
     uvSim.OutputTextblock.Text += $"\nProgram Counter: {uvSim.ProgramCounter}\n";
 }
 // Cameron Prestera
 public static void Divide(this UVSimModel uvSim, string operand)
 {
     uvSim.Accumulator /= int.Parse(uvSim.Memory[int.Parse(operand)]);
 }
Example #23
0
        // Ben Thornhill
        private static void RunCommand(this UVSimModel uvSim, string instruction)
        {
            string breakPoint = instruction.Substring(2, 2);

            if (breakPoint == "11")
            {
                throw new Exception("Breakpoint was triggered.\n Please select 'Continue' to resume execution");
            }

            string operation = instruction.Substring(0, 2);
            string operand   = instruction.Substring(4, 4);

            switch (operation)
            {
            case "10":
                uvSim.Read(operand);
                break;

            case "11":
                uvSim.Write(operand);
                break;

            case "20":
                uvSim.Load(operand);
                break;

            case "21":
                uvSim.Store(operand);
                break;

            case "30":
                uvSim.Add(operand);
                break;

            case "31":
                uvSim.Subtract(operand);
                break;

            case "32":
                uvSim.Divide(operand);
                break;

            case "33":
                uvSim.Multiply(operand);
                break;

            case "34":
                uvSim.Remainder(operand);
                break;

            case "35":
                uvSim.Exponent(operand);
                break;

            case "40":
                uvSim.Branch(operand);
                break;

            case "41":
                uvSim.BranchNeg(operand);
                break;

            case "42":
                uvSim.BranchZero(operand);
                break;

            case "43":
                uvSim.Halt();
                break;
            }
        }
 public static void Subtract(this UVSimModel uvSim, string operand) /* accumulator -= int.Parse(memory[operand]); */ }
 // Cameron Prestera
 public static void Multiply(this UVSimModel uvSim, string operand)
 {
     uvSim.Accumulator *= int.Parse(uvSim.Memory[int.Parse(operand)]);
 }
 //Jaren Flaker
 public static void Remainder(this UVSimModel uvSim, string operand)
 {
     uvSim.Accumulator %= int.Parse(uvSim.Memory[int.Parse(operand)]);
 }
 //Jaren Flaker
 public static void Exponent(this UVSimModel uvSim, string operand)
 {
     int exponent = int.Parse (uvSim.Memory[int.Parse(operand)]);
     uvSim.Accumulator = (int)Math.Pow((double)uvSim.Accumulator, (double)exponent);
 }
Example #28
0
 public static string DisplayOutput(this UVSimModel uvSim)
 {
     return(uvSim.Output);
 }
Example #29
0
 //Control Operations
 //Jaren Flaker
 public static void Branch(this UVSimModel uvSim, string operand)
 {
     uvSim.ProgramCounter = int.Parse(operand);
 }
Example #30
0
 //Jaren Flaker
 public static void Halt(this UVSimModel uvSim)
 {
     uvSim.ProgramCounter = -666;
 }