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); } }
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); }
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); }