示例#1
0
        protected override void Compile(Program program)
        {
            if (Operands[0].OperandType != OperandType.Register)
            {
                throw new NotSupportedException();
            }
            var w       = RegistersManager.GetW(Operands[0].Value);
            var regCode = RegistersManager.GetCode(Operands[0].Value);

            BinaryCode.AddBits(1, 1, 0);
            if (Operands[1].OperandType == OperandType.Direct)
            {
                var dir = int.Parse(Operands[1].Value);
                if (dir == 1)
                {
                    BinaryCode.AddBits(1, 0, 0, 0, w, 1, 1, 1, 1, 1);
                    BinaryCode.AddBits(regCode);
                }
                else
                {
                    BinaryCode.AddBits(0, 0, 0, 0, w, 1, 1, 1, 1, 1);
                    BinaryCode.AddBits(regCode);
                    BinaryCode.AddBytes(dir.InReverseByteOrder(1));
                }
            }
            else if (Operands[1].Value == "cl")
            {
                BinaryCode.AddBits(1, 0, 0, 1, w, 1, 1, 1, 1, 1);
                BinaryCode.AddBits(regCode);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
示例#2
0
// CUT begin
    static bool DoTest(string message, string[] __expected)
    {
        DateTime   startTime = DateTime.Now;
        Exception  exception = null;
        BinaryCode instance  = new BinaryCode();

        string[] __result = new string[] { };
        try {
            __result = instance.decode(message);
        }
        catch (Exception e) { exception = e; }
        TimeSpan __elapsed = new TimeSpan(DateTime.Now.Ticks - startTime.Ticks);

        if (exception != null)
        {
            Console.Error.WriteLine("RUNTIME ERROR!");
            Console.Error.WriteLine(exception);
            return(false);
        }
        else if (Equals(__result, __expected))
        {
            Console.Error.WriteLine("PASSED! " + string.Format("({0:0.00} seconds)", __elapsed.TotalSeconds));
            return(true);
        }
        else
        {
            Console.Error.WriteLine("FAILED! " + string.Format("({0:0.00} seconds)", __elapsed.TotalSeconds));
            Console.Error.WriteLine("           Expected: " + ToString(__expected));
            Console.Error.WriteLine("           Received: " + ToString(__result));
            return(false);
        }
    }
示例#3
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        void RunTestWithInputs(string message, string[] expected)
        {
            BinaryCode target = new BinaryCode();

            string[] actual;
            actual = target.decode(message);
            CollectionAssert.AreEqual(expected, actual);
        }
示例#4
0
 protected override void Compile(Program program)
 {
     if (Operands[0].OperandType != OperandType.Memory)
     {
         throw new ArgumentException();
     }
     BinaryCode.AddBytes(0xEB);
     BinaryCode.AddBytes((program.Labels[Operands[0].Value] - Address).InReverseByteOrder(program.LabelSize));
 }
示例#5
0
 protected override void Compile(Program program)
 {
     if (Operands[0].OperandType != OperandType.Register)
     {
         throw new NotSupportedException();
     }
     BinaryCode.AddBits(0, 1, 0, 1, 0);
     BinaryCode.AddBits(RegistersManager.GetCode(Operands[0].Value));
 }
示例#6
0
// END CUT HERE
// BEGIN CUT HERE
    public static void Main()
    {
        try {
            BinaryCode ___test = new BinaryCode();
            ___test.run_test(-1);
        } catch (Exception e) {
//Console.WriteLine(e.StackTrace);
            Console.WriteLine(e.ToString());
        }
    }
示例#7
0
 // END CUT HERE
 // BEGIN CUT HERE
 public static void Main()
 {
     try {
     BinaryCode ___test = new BinaryCode();
     ___test.run_test(-1);
     } catch(Exception e) {
     //Console.WriteLine(e.StackTrace);
     Console.WriteLine(e.ToString());
     }
 }
        public void BinaryCodeFiiling()
        {
            var binaryCode = new BinaryCode();

            binaryCode
            .AddBits(0, 1, 1)
            .AddBytes(15)
            .AddBits(1)
            .AddBytes(23);
            binaryCode.ToBytes().Should().BeEquivalentTo(new byte[] { 96, 15, 128, 23 });
        }
示例#9
0
 protected override void Compile(Program program)
 {
     if ((Operands[0].Value == "al" || Operands[0].Value == "ax") & Operands[1].OperandType == OperandType.Direct)
     {
         var w = RegistersManager.GetW(Operands[0].Value);
         BinaryCode.AddBits(0, 0, 0, 0, 0, 1, 0, w);
         BinaryCode.AddBytes(int.Parse(Operands[1].Value).InReverseByteOrder(w + 1));
     }
     else if (Operands.All(x => x.OperandType == OperandType.Register))
     {
         var w = Operands.ToW();
         BinaryCode.AddBits(0, 0, 0, 0, 0, 0, 1, w, 1, 1);
         BinaryCode.AddBits(RegistersManager.GetCode(Operands[0].Value));
         BinaryCode.AddBits(RegistersManager.GetCode(Operands[1].Value));
     }
     else
     {
         throw new NotSupportedException();
     }
 }
示例#10
0
        protected override void Compile(Program program)
        {
            if (Operands[0].OperandType == OperandType.Direct)
            {
                throw new ArgumentException();
            }

            var w = Operands.ToW();

            if (Operands.Count(x => x.Value == "al" || x.Value == "ax") == 1)
            {
                var d = Operands[0].OperandType == OperandType.Memory ? 1 : 0;
                BinaryCode.AddBits(1, 0, 1, 0, 0, 0, d, w);
                var inMemoryOperand = Operands.First(x => x.OperandType == OperandType.Memory);
                var reference       = program.Labels[inMemoryOperand.Value];
                BinaryCode.AddBytes(reference.InReverseByteOrder(program.ReferenceSize));
                program.ObjectFile.SegmentsBlock.CodeSegment.AddReference(
                    new BinaryCode(0xC4)
                    .AddBytes((Address - program.DataSize + 1 - reference).InReverseByteOrder(1))
                    .AddBytes(0x14, 0x01, 0x02));
            }
            else if (Operands[0].OperandType == OperandType.Register)
            {
                if (Operands[1].OperandType == OperandType.Direct)
                {
                    BinaryCode.AddBits(1, 0, 1, 1, w);
                    BinaryCode.AddBits(RegistersManager.GetCode(Operands[0].Value));
                    BinaryCode.AddBytes(int.Parse(Operands[1].Value).InReverseByteOrder(w + 1));
                }
                else if (Operands[1].OperandType == OperandType.Register)
                {
                    BinaryCode.AddBits(1, 0, 0, 0, 1, 0, 1, w, 1, 1);
                    BinaryCode.AddBits(RegistersManager.GetCode(Operands[0].Value));
                    BinaryCode.AddBits(RegistersManager.GetCode(Operands[1].Value));
                }
            }
            else
            {
                throw new NotSupportedException();
            }
        }
示例#11
0
 protected override void Compile(Program program)
 {
     BinaryCode.AddBytes(0xFD);
 }
示例#12
0
 public void AddReference(BinaryCode binaryCode)
 {
     InitReferenceRecordIfNull();
     referenceRecord.AddBinaryCode(binaryCode);
 }
示例#13
0
 public void AddDefinition(BinaryCode binaryCode)
 {
     InitDefinitionRecordIfNull();
     definitionRecord.AddBinaryCode(binaryCode);
 }
示例#14
0
 public override int GetHashCode()
 {
     return(BinaryCode != null?BinaryCode.GetHashCode() : 0);
 }