コード例 #1
0
        public void ToAssembly_GivenEq_ReturnsTranslatedAssembly(int eqCount)
        {
            var expected = new string []
            {
                "// eq",
                "@SP",
                "AM=M-1",
                "D=M",
                "@SP",
                "A=M-1",
                "D=M-D",
                $"@EQ_{eqCount}",
                "D;JEQ",
                "@SP",
                "A=M-1",
                "M=0",
                $"@EQ_END_{eqCount}",
                "0;JMP",
                $"(EQ_{eqCount})",
                "@SP",
                "A=M-1",
                "M=-1",
                $"(EQ_END_{eqCount})",
                ""
            };

            var result = new ArithmeticCommandTranslatorBuilder()
                         .WithEqCount(eqCount)
                         .CreateSut()
                         .ToAssembly("eq");

            Assert.Equal(expected, result);
        }
コード例 #2
0
        public void ToAssembly_GivenLt_ReturnsTranslatedAssembly(int ltCount)
        {
            var expected = new string []
            {
                "// lt",
                "@SP",
                "AM=M-1",
                "D=M",
                "@SP",
                "A=M-1",
                "D=M-D",
                $"@LT_{ltCount}",
                "D;JLT",
                "@SP",
                "A=M-1",
                "M=0",
                $"@LT_END_{ltCount}",
                "0;JMP",
                $"(LT_{ltCount})",
                "@SP",
                "A=M-1",
                "M=-1",
                $"(LT_END_{ltCount})",
                ""
            };

            var result = new ArithmeticCommandTranslatorBuilder()
                         .WithLtCount(ltCount)
                         .CreateSut()
                         .ToAssembly("lt");

            Assert.Equal(expected, result);
        }
コード例 #3
0
        public void ToAssembly_GivenNeg_ReturnsTranslatedAssembly()
        {
            var expected = new string []
            {
                "// neg",
                "@SP",
                "A=M-1",
                "M=-M",
                ""
            };

            var result = new ArithmeticCommandTranslatorBuilder()
                         .CreateSut()
                         .ToAssembly("neg");

            Assert.Equal(expected, result);
        }