Beispiel #1
0
        public Instruction(IWordStream stream, ulong address)
        {
            var bits = new BitStream(stream.ReadWord(address++));

            this.Length     = 1;
            this.Code       = bits.ReadU8(8);
            this.Definition = InstructionDefinition.Find(this.Code);

            if (this.Definition.ParameterCount > 0)
            {
                this.Parameter1 = this.DecodeParameter(stream, ref address, bits);
            }
            if (this.Definition.ParameterCount > 1)
            {
                this.Parameter2 = this.DecodeParameter(stream, ref address, bits);
            }
            if (this.Definition.ParameterCount > 2)
            {
                this.Parameter3 = this.DecodeParameter(stream, ref address, bits);
            }

            bits.Advance((3 - this.Definition.ParameterCount) * 8);

            if (bits.ReadU1())
            {
                this.ConditionalZero      = bits.ReadU1();
                this.ConditionalParameter = this.DecodeParameter(stream, ref address, bits);
            }
        }
Beispiel #2
0
        private Parameter DecodeParameter(IWordStream stream, ref ulong address, BitStream bits)
        {
            var para = new Parameter()
            {
                IsRIPRelative = bits.ReadU1(),
                IsIndirect    = bits.ReadU1(),
                Type          = (ParameterType)bits.ReadU8(2),
                Register      = (Register)bits.ReadU8(5)
            };

            if (para.Type == ParameterType.Calculated)
            {
                this.DecodeCalculatedParameter(stream, ref address, para);

                this.Length++;
            }
            else if (para.Type == ParameterType.Literal)
            {
                para.Literal = stream.ReadWord(address++);

                this.Length++;
            }

            return(para);
        }
Beispiel #3
0
        private void DecodeCalculatedParameter(IWordStream stream, ref ulong address, Parameter parameter)
        {
            var bits = new BitStream(stream.ReadWord(address++));

            parameter.Base   = this.DecodeCalculatedOperand(stream, ref address, bits);
            parameter.Index  = this.DecodeCalculatedOperand(stream, ref address, bits);
            parameter.Scale  = this.DecodeCalculatedOperand(stream, ref address, bits);
            parameter.Offset = this.DecodeCalculatedOperand(stream, ref address, bits);
        }
Beispiel #4
0
 private Parameter.Calculated DecodeCalculatedOperand(IWordStream stream, ref ulong address, BitStream bits) => new Parameter.Calculated(bits.ReadU1(), this.DecodeParameter(stream, ref address, bits));