示例#1
0
文件: Assembler.cs 项目: wtf3505/iced
        /// <summary>
        /// Add an instruction directly to the flow of instructions.
        /// </summary>
        /// <param name="instruction"></param>
        public void AddInstruction(ref Instruction instruction)
        {
            if (!_label.IsEmpty && _definedAnonLabel)
            {
                throw new InvalidOperationException("You can't create both an anonymous label and a normal label");
            }
            if (!_label.IsEmpty)
            {
                instruction.IP = _label.Id;
            }
            else if (_definedAnonLabel)
            {
                instruction.IP = _currentAnonLabel.Id;
            }

            // Setup prefixes
            if (_nextPrefixFlags != PrefixFlags.None)
            {
                if ((_nextPrefixFlags & PrefixFlags.Lock) != 0)
                {
                    instruction.HasLockPrefix = true;
                }
                if ((_nextPrefixFlags & PrefixFlags.Xacquire) != 0)
                {
                    instruction.HasXacquirePrefix = true;
                }
                if ((_nextPrefixFlags & PrefixFlags.Xrelease) != 0)
                {
                    instruction.HasXreleasePrefix = true;
                }
                if ((_nextPrefixFlags & PrefixFlags.Rep) != 0)
                {
                    instruction.HasRepPrefix = true;
                }
                else if ((_nextPrefixFlags & PrefixFlags.Repe) != 0)
                {
                    instruction.HasRepePrefix = true;
                }
                else if ((_nextPrefixFlags & PrefixFlags.Repne) != 0)
                {
                    instruction.HasRepnePrefix = true;
                }
                if ((_nextPrefixFlags & PrefixFlags.Bnd) != 0)
                {
                    instruction.HasRepnePrefix = true;
                }
                if ((_nextPrefixFlags & PrefixFlags.Notrack) != 0)
                {
                    instruction.SegmentPrefix = Register.DS;
                }
            }

            _instructions.Add(instruction);
            _label            = default;
            _definedAnonLabel = false;
            _nextPrefixFlags  = PrefixFlags.None;
        }
示例#2
0
        /// <summary>
        /// Add an instruction directly to the flow of instructions.
        /// </summary>
        /// <param name="instruction"></param>
        public void AddInstruction(ref Instruction instruction)
        {
            if (!currentLabel.IsEmpty && definedAnonLabel)
            {
                throw new InvalidOperationException("You can't create both an anonymous label and a normal label");
            }
            if (!currentLabel.IsEmpty)
            {
                instruction.IP = currentLabel.Id;
            }
            else if (definedAnonLabel)
            {
                instruction.IP = currentAnonLabel.Id;
            }

            // Setup prefixes
            if (prefixFlags != PrefixFlags.None)
            {
                if ((prefixFlags & PrefixFlags.Lock) != 0)
                {
                    instruction.HasLockPrefix = true;
                }
                if ((prefixFlags & PrefixFlags.Repe) != 0)
                {
                    instruction.HasRepePrefix = true;
                }
                else if ((prefixFlags & PrefixFlags.Repne) != 0)
                {
                    instruction.HasRepnePrefix = true;
                }
                if ((prefixFlags & PrefixFlags.Notrack) != 0)
                {
                    instruction.SegmentPrefix = Register.DS;
                }
            }

            instructions.Add(instruction);
            currentLabel     = default;
            definedAnonLabel = false;
            prefixFlags      = PrefixFlags.None;
        }