示例#1
0
        // Read two numbers and sum them
        public void MipsGenerationTestAdd2()
        {
            // Names
            var test_name   = "test3";
            var file_name   = Path.Combine("TestCases", $"{ test_name }.asm");
            var input_file  = Path.Combine("TestCases", $"{ test_name }.in");
            var output_file = Path.Combine("TestCases", $"{ test_name }.out");
            var answer_file = Path.Combine("TestCases", $"{ test_name }.ans");

            Helper.CreateFile(input_file, "13\r\n2");

            // Code
            Helper.CreateFile(file_name, MipsGenerationHelper.NewScript()
                              .TextSection()
                              .MainTag()
                              .ReadInt(MipsRegisterSet.a0)
                              .ReadInt(MipsRegisterSet.v0)
                              .Add(MipsRegisterSet.a0, MipsRegisterSet.v0)
                              .PrintInt(MipsRegisterSet.a0)
                              .Exit());

            // Answer
            Helper.CreateFile(answer_file, "15");

            // Running
            Helper.RunSpim(file_name, input_file: input_file, output_file: output_file);

            // Normalize --> deleting unuseful lines at the beginning of the file
            Helper.Normalize(output_file);

            // Checking
            Assert.True(Helper.CompareFiles(output_file, answer_file));
        }
示例#2
0
        // Read two numbers (a, b) and return a + b, a - b, a * b, a / b
        public void MipsGenerationTestArithmetic1()
        {
            // Names
            var test_name   = "test6";
            var file_name   = Path.Combine("TestCases", $"{ test_name }.asm");
            var input_file  = Path.Combine("TestCases", $"{ test_name }.in");
            var output_file = Path.Combine("TestCases", $"{ test_name }.out");
            var answer_file = Path.Combine("TestCases", $"{ test_name }.ans");

            Helper.CreateFile(input_file, "13\r\n2");

            // Code
            Helper.CreateFile(file_name, MipsGenerationHelper.NewScript()
                              .DataSection()
                              .AddData("newline", new List <(string, object)> {
                MipsGenerationHelper.AddStringData("\\n")
            })