public void ParserCanParseDataAddress()
        {
            IParser parser = new Parser();

            var myProgram =
                "address: 0x48" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal((uint)0x12, parser.KernelIndex);
        }
        public void ParseCPS()
        {
            IParser parser = new Parser();

            var myProgram =
                "CPS 0x12" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xf1020012, output[0]);
        }
        public void ParseCPSID()
        {
            IParser parser = new Parser();

            var myProgram =
                "CPSID 0x011" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xf10c00c0, output[0]);
        }
        public void ParseCPSIE()
        {
            IParser parser = new Parser();

            var myProgram =
                "CPSIE 0x110" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xf1080180, output[0]);
        }
        public void ParserCanParseDataByteGreaterThanWordSize()
        {
            IParser parser = new Parser();

            var myProgram =
                "byte: 0x48, 0x69, 0x20, 0x48, 0x69, 0x20" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal((uint)0x48206948, output[0]);
            Assert.Equal((uint)0x00002069, output[1]);
        }
        public void ParserParseMOVTParse0()
        {
            IParser parser = new Parser();

            var myProgram =
                "MOVT r0, 0x0" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe3400000, output[0]);
        }
        public void ParserParseADDI3()
        {
            IParser parser = new Parser();

            var myProgram =
                "ADDI a1, a4, 0x3f000000" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal((uint)0xe283043f, output[0]);
        }
        public void ParserWillThrowIfAddressIsNotFollowedByANumber()
        {
            IParser parser = new Parser();

            var myProgram =
                "address:" + Environment.NewLine;

            Assert.Throws<SyntaxException>(() =>
            {
                var output = parser.Parse(myProgram);
            });
        }
        public void ParserParseSUBSParse01()
        {
            IParser parser = new Parser();

            var myProgram =
                "SUBS r3, r3, 0x01" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe2533001, output[0]);
        }
Example #10
0
        public void ParserParseROR()
        {
            IParser parser = new Parser();

            var myProgram =
                "ROR r1, r2, #28" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe1a01e62, output[0]);
        }
Example #11
0
        public void ParserParseMULRSParser0r0()
        {
            IParser parser = new Parser();

            var myProgram =
                "MULRS r0, r0, r1" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe0001090, output[0]);
        }
Example #12
0
        public void ParserParseLab7()
        {
            IParser parser = new Parser();

            var myProgram =
                "MOVW r0, 0x0" + Environment.NewLine +
                "MOVT r0, 0x3f20" + Environment.NewLine +
                "MOVW r1, 0x0" + Environment.NewLine +
                "MOVT r1, 0x20" + Environment.NewLine +
                "" + Environment.NewLine +
                "STR r1, r0, 0x10" + Environment.NewLine +
                "MOVW r2, 0x8000" + Environment.NewLine +
                "" + Environment.NewLine +
                "loop: STR r2, r0, 0x20" + Environment.NewLine +
                "MOVW r3, 0x0" + Environment.NewLine +
                "MOVT r3, 0x10" + Environment.NewLine +
                "wait1: SUBS r3, r3, 0x01" + Environment.NewLine +
                "  BNE wait1" + Environment.NewLine +
                "" + Environment.NewLine +
                "STR r2, r0, 0x2c" + Environment.NewLine +
                "" + Environment.NewLine +
                "MOVW r3, 0x0" + Environment.NewLine +
                "MOVT r3, 0x10" + Environment.NewLine +
                "wait2: SUBS r3, r3, 0x01" + Environment.NewLine +
                "  BNE wait2" + Environment.NewLine +
                "" + Environment.NewLine +
                "BAL loop" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe3000000, output[0]);
            Assert.Equal(0xe3430f20, output[1]);
            Assert.Equal(0xe3001000, output[2]);
            Assert.Equal(0xe3401020, output[3]);
            Assert.Equal(0xe5801010, output[4]);
            Assert.Equal(0xe3082000, output[5]);
            Assert.Equal(0xe5802020, output[6]);
            Assert.Equal(0xe3003000, output[7]);
            Assert.Equal(0xe3403010, output[8]);
            Assert.Equal(0xe2533001, output[9]);
            Assert.Equal((uint)0x1afffffd, output[10]);
            Assert.Equal(0xe580202c, output[11]);
            Assert.Equal(0xe3003000, output[12]);
            Assert.Equal(0xe3403010, output[13]);
            Assert.Equal(0xe2533001, output[14]);
            Assert.Equal((uint)0x1afffffd, output[15]);
            Assert.Equal(0xeafffff4, output[16]);
        }
Example #13
0
        public void ParserParseCMPI()
        {
            IParser parser = new Parser();

            var myProgram =
                "CMPI a4, 0x4" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe3530004, output[0]);
        }
Example #14
0
        public void ParserParseBNEParseWithLabelAfter()
        {
            IParser parser = new Parser();

            var myProgram =
                "BNE loop" + Environment.NewLine +
                "loop: MOVW r0, 0x0" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal((uint)0x1affffff, output[0]);
            Assert.Equal(0xe3000000, output[1]);
        }
Example #15
0
        public void ParserParseBNEParseNoLabel()
        {
            IParser parser = new Parser();

            var myProgram =
                "BNE loop" + Environment.NewLine;

            Assert.Throws(typeof(SyntaxException), () =>
            {
                parser.Parse(myProgram);
            });
        }
Example #16
0
        public void ParserParseBLParseWithLabel()
        {
            IParser parser = new Parser();

            var myProgram =
                "loop: MOVW r0, 0x0" + Environment.NewLine +
                "BL loop" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe3000000, output[0]);
            Assert.Equal(0xebfffffd, output[1]);
        }
Example #17
0
        public void ParserParseMOVWParse1()
        {
            IParser parser = new Parser();

            var myProgram =
                "MOVW r1, 0x01" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe3001001, output[0]);
        }
Example #18
0
        public void ParserParseORRSImmediate()
        {
            IParser parser = new Parser();

            var myProgram =
                "ORRS r1, r4, 0x01" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe3941001, output[0]);
        }
Example #19
0
        public void ParserParseMOVWTooLarge()
        {
            IParser parser = new Parser();

            var myProgram =
                "MOVW r0, 0x10000" + Environment.NewLine;

            Assert.Throws(typeof(SyntaxException), () =>
            {
                var output = parser.Parse(myProgram);
            });
        }
Example #20
0
        public void ParserParseAND()
        {
            IParser parser = new Parser();

            var myProgram =
                "ANDS a3, a3, 0x20" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe2122020, output[0]);
        }
Example #21
0
        public void ParserParseORRRSRegister()
        {
            IParser parser = new Parser();

            var myProgram =
                "ORRRS r1, r4, r3" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe1941003, output[0]);
        }
Example #22
0
        public void ParserParseLabelReturnsCorrectIndex()
        {
            IParser parser = new Parser();

            var myProgram =
                "MOVT r0, 0x3f20" + Environment.NewLine +
                "loop: MOVW r0, 0x0" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Contains("loop", parser.LabelTable.Keys);
            Assert.Equal((uint)1, parser.LabelTable["loop"]);
        }
Example #23
0
        public void ParserParsePUSHR1()
        {
            IParser parser = new Parser();

            var myProgram =
                "PUSH r1" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe52d1004, output[0]);
        }
Example #24
0
        public void ParserParseLDRBPositive()
        {
            IParser parser = new Parser();

            var myProgram =
                "LDRB a1, v1, 0x0" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe5d40000, output[0]);
        }
Example #25
0
        public void ParserParseSTRParse10()
        {
            IParser parser = new Parser();

            var myProgram =
                "STR r1, r0, 0x10" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe5801010, output[0]);
        }
Example #26
0
        public void ParserParseLDRPositive()
        {
            IParser parser = new Parser();

            var myProgram =
                "LDR v4, sp, 0x8" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe59d7008, output[0]);
        }
Example #27
0
        public void ParserReturnsUIntArray()
        {
            IParser parser = new Parser();
            var result = parser.Parse("");

            Assert.IsType(typeof(uint[]), result);
        }
Example #28
0
        public void ParserParseMOVNotRegr18()
        {
            IParser parser = new Parser();

            var myProgram =
                "MOV r0, r18" + Environment.NewLine;

            Assert.Throws(typeof(SyntaxException), () =>
            {
                var output = parser.Parse(myProgram);
            });
        }
Example #29
0
        public void ParserWillThrowIfByteValueIsTooBig()
        {
            IParser parser = new Parser();

            var myProgram =
                "byte: 0x100, 0x50, 0x40, 0x0" + Environment.NewLine;

            Assert.Throws<SyntaxException>(() =>
            {
                var output = parser.Parse(myProgram);
            });
        }
Example #30
0
        public void ParserParseMOVParser0r1()
        {
            IParser parser = new Parser();

            var myProgram =
                "MOV r0, r1" + Environment.NewLine;

            var output = parser.Parse(myProgram);

            Assert.Equal(0xe1a00001, output[0]);
        }