Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
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));
 }
Ejemplo n.º 3
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();
     }
 }
Ejemplo n.º 4
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();
            }
        }