예제 #1
0
        protected override byte[] GetTranslatedBytesForMemIm(Identifier identifier, Constant constant)
        {
            int bytesCount = 6;

            byte[] translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte(
                string.Format("1100011{0}", identifier.W));

            // mod reg r/m
            translatedBytes[1] = BitStringHelper.BitStringToByte("00000110");

            // Address.
            translatedBytes[2] = 0x00;
            translatedBytes[3] = 0x00;

            translatedBytes[4] = constant.Bytes[0];

            if (identifier.Type == IdentifierType.Byte)
            {
                translatedBytes[5] = 0x90; // NOP;
            }
            else if (constant.Bytes.Length == 2)
            {
                translatedBytes[5] = constant.Bytes[1];
            }

            return(translatedBytes);
        }
예제 #2
0
        protected virtual byte[] GetTranslatedBytesForMemIm(Identifier identifier, Constant constant)
        {
            int bytesCount = (identifier.Type == IdentifierType.Byte) ? 5 : 4 + constant.Bytes.Length;

            byte[] translatedBytes = new byte[bytesCount];

            int s = (identifier.Type == IdentifierType.Word && constant.Bytes.Length == 1) ?
                    1 : 0;

            translatedBytes[0] = BitStringHelper.BitStringToByte(
                string.Format(MemImFormat, s, identifier.W));

            // mod reg r/m
            translatedBytes[1] = BitStringHelper.BitStringToByte(
                string.Format("00{0}110", RegFieldForIm));

            // Address.
            translatedBytes[2] = 0x00;
            translatedBytes[3] = 0x00;

            translatedBytes[4] = constant.Bytes[0];

            if (translatedBytes.Length == 6)
            {
                translatedBytes[5] = constant.Bytes[1];
            }

            return(translatedBytes);
        }
예제 #3
0
        private void translateForRegRegIm(TranslationContext context, int startPos)
        {
            Register reg1     = null;
            Register reg2     = null;
            Constant constant = null;

            context.Checker.CheckRegRegIm(Tokens, startPos, out reg1, out reg2, out constant);

            int bytesCount = (reg1.W == WValueStore.ZERO) ? 3 : 2 + constant.Bytes.Length;

            byte[] translatedBytes = new byte[bytesCount];

            int s = (reg1.W == WValueStore.ONE && constant.Bytes.Length == 1) ?
                    1 : 0;

            translatedBytes[0] = BitStringHelper.BitStringToByte(
                string.Format("011010{0}1", s));

            translatedBytes[1] = BitStringHelper.BitStringToByte(
                string.Format("11{0}{1}", reg1, reg2));

            translatedBytes[2] = constant.Bytes[0];

            if (translatedBytes.Length == 4)
            {
                translatedBytes[3] = constant.Bytes[1];
            }

            context.AddTranslatedUnit(translatedBytes);
        }
예제 #4
0
        private void translateForRegMemIm(TranslationContext context, int startPos)
        {
            Register   reg      = null;
            Identifier id       = null;
            Constant   constant = null;

            context.Checker.CheckRegMemIm(Tokens, startPos, out reg, out id, out constant);

            int bytesCount = (reg.W == WValueStore.ZERO) ? 5 : 4 + constant.Bytes.Length;

            byte[] translatedBytes = new byte[bytesCount];

            int s = (reg.W == WValueStore.ONE && constant.Bytes.Length == 1) ?
                    1 : 0;

            translatedBytes[0] = BitStringHelper.BitStringToByte(
                string.Format("011010{0}1", s));

            translatedBytes[1] = BitStringHelper.BitStringToByte(
                string.Format("00{0}110", reg));

            // Address.
            translatedBytes[2] = 0x00;
            translatedBytes[3] = 0x00;

            translatedBytes[4] = constant.Bytes[0];

            if (translatedBytes.Length == 6)
            {
                translatedBytes[5] = constant.Bytes[1];
            }

            context.AddTranslatedUnit(translatedBytes);
        }
예제 #5
0
        protected override byte[] GetTranslatedBytes()
        {
            int bytesCount = 3;

            byte[] translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte("11101001");

            return(translatedBytes);
        }
예제 #6
0
        protected override byte[] GetTranslatedBytes()
        {
            int bytesCount = 4;

            byte[] translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte("00001111");
            translatedBytes[1] = BitStringHelper.BitStringToByte(
                string.Format("1000{0}",
                              SecondBytePlaceholder));

            return(translatedBytes);
        }
예제 #7
0
        protected override void TranslateCommand(TranslationContext context, int startPos)
        {
            Constant constant = null;

            context.Checker.CheckIm8(Tokens, startPos, out constant);

            int bytesCount = 2;

            byte[] translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte("11001101");
            translatedBytes[1] = constant.Bytes[0];

            context.AddTranslatedUnit(translatedBytes);
        }
예제 #8
0
        protected override void TranslateCommand(TranslationContext context, int startPos)
        {
            Register   register   = null;
            Identifier identifier = null;

            context.Checker.CheckRegMemAddress(Tokens, startPos, out register, out identifier);

            int bytesCount = 4;

            byte[] translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte("10001101");
            translatedBytes[1] = BitStringHelper.BitStringToByte(
                string.Format("{0}{1}{2}", "00", register, "110"));

            context.AddTranslatedUnit(translatedBytes);
        }
예제 #9
0
        private void translateForAMem(TranslationContext context, int startPos)
        {
            Identifier identifier = null;

            context.Checker.CheckMem(Tokens, startPos, out identifier);

            int bytesCount = 4;

            byte[] translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte(
                string.Format("1111011{0}", identifier.W));

            translatedBytes[1] = BitStringHelper.BitStringToByte("00101110");

            context.AddTranslatedUnit(translatedBytes);
        }
예제 #10
0
        private void translateForReg(TranslationContext context, int startPos)
        {
            Register reg = null;

            context.Checker.CheckReg(Tokens, startPos, out reg);

            int bytesCount = 2;

            byte[] translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte(
                string.Format(OperationCodeFormat, reg.W));

            translatedBytes[1] = BitStringHelper.BitStringToByte(
                string.Format(AddressingByteFormat, "11", reg));

            context.AddTranslatedUnit(translatedBytes);
        }
예제 #11
0
        protected override byte[] GetTranslatedBytesForRegIm(Register reg, Constant constant)
        {
            // 2 or 3
            int bytesCount = 2 + reg.W;

            byte[] translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte(
                string.Format("1011{0}{1}", reg.W, reg));

            translatedBytes[1] = constant.Bytes[0];

            if (constant.Bytes.Length == 2)
            {
                translatedBytes[2] = constant.Bytes[1];
            }

            return(translatedBytes);
        }
예제 #12
0
        private void translateForRegReg(TranslationContext context, int startPos)
        {
            Register reg1 = null;
            Register reg2 = null;

            context.Checker.CheckRegReg(Tokens, startPos, out reg1, out reg2);

            int bytesCount      = 3;
            var translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte("00001111");
            translatedBytes[1] = BitStringHelper.BitStringToByte("10101111");

            // mod reg r/m
            translatedBytes[2] = BitStringHelper.BitStringToByte(
                string.Format("{0}{1}{2}", "11", reg1, reg2));

            context.AddTranslatedUnit(translatedBytes);
        }
예제 #13
0
        private void translateForMemReg(TranslationContext context, int startPos)
        {
            Identifier memCell = null;
            Register   reg     = null;

            context.Checker.CheckMemReg(Tokens, startPos, out memCell, out reg);

            int bytesCount = 4;

            byte[] translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte(
                string.Format(MemRegFormat, reg.W));

            // mod reg r/m
            translatedBytes[1] = BitStringHelper.BitStringToByte(
                string.Format("{0}{1}{2}", "00", reg, "110"));

            context.AddTranslatedUnit(translatedBytes);
        }
예제 #14
0
        private void translateForRegMem(TranslationContext context, int startPos)
        {
            Register   reg        = null;
            Identifier identifier = null;

            context.Checker.CheckRegMem(Tokens, startPos, out reg, out identifier);

            int bytesCount = 5;

            byte[] translatedBytes = new byte[bytesCount];

            translatedBytes[0] = BitStringHelper.BitStringToByte("00001111");
            translatedBytes[1] = BitStringHelper.BitStringToByte("10101111");

            // mod reg r/m
            translatedBytes[2] = BitStringHelper.BitStringToByte(
                string.Format("{0}{1}{2}", "00", reg, "110"));

            context.AddTranslatedUnit(translatedBytes);
        }
예제 #15
0
        public override byte[] Parse(string value)
        {
            string clearedValue = value.TrimStart('0')
                                  .TrimEnd('b', 'B');

            if (clearedValue.Length == 0)
            {
                return(new byte[] { 0 });
            }

            int remainingBitsCount = clearedValue.Length % BITS_IN_BYTE;
            int bytesCount         = clearedValue.Length / BITS_IN_BYTE +
                                     ((remainingBitsCount != 0) ? 1 : 0);

            if (bytesCount > 2)
            {
                throw new TranslationErrorException(
                          string.Format(Resources.ConstantOverflowMsgFormat, value));
            }

            byte[] bytes  = new byte[bytesCount];
            int    endPos = clearedValue.Length;

            for (int i = 0; i < bytes.Length - 1; ++i)
            {
                var bitString = clearedValue.Substring(endPos - BITS_IN_BYTE, BITS_IN_BYTE);
                bytes[i] = BitStringHelper.BitStringToByte(bitString);

                endPos -= BITS_IN_BYTE;
            }

            int    countToSubstr = (remainingBitsCount == 0) ? BITS_IN_BYTE : remainingBitsCount;
            string lastBitString = clearedValue.Substring(0, countToSubstr);

            bytes[bytes.Length - 1] = BitStringHelper.BitStringToByte(lastBitString);

            return(bytes);
        }
예제 #16
0
        protected virtual byte[] GetTranslatedBytesForRegIm(Register reg, Constant constant)
        {
            int bytesCount = (reg.W == WValueStore.ZERO) ? 3 : 2 + constant.Bytes.Length;

            byte[] translatedBytes = new byte[bytesCount];

            int s = (reg.W == WValueStore.ONE && constant.Bytes.Length == 1) ? 1 : 0;

            translatedBytes[0] = BitStringHelper.BitStringToByte(
                string.Format(RegImFormat, s, reg.W));

            translatedBytes[1] = BitStringHelper.BitStringToByte(
                string.Format("11{0}{1}", RegFieldForIm, reg));

            translatedBytes[2] = constant.Bytes[0];

            if (translatedBytes.Length == 4)
            {
                translatedBytes[3] = constant.Bytes[1];
            }

            return(translatedBytes);
        }