Beispiel #1
0
        public static OpcodeEncoder AppendSIB(this OpcodeEncoder encoder, int scale, Register index, Register @base)
        {
            Debug.Assert(scale == 1 || scale == 2 || scale == 4 || scale == 8);

            int svalue = 0;

            if (scale == 1)
            {
                svalue = 0;
            }
            else if (scale == 2)
            {
                svalue = 1;
            }
            else if (scale == 4)
            {
                svalue = 2;
            }
            else if (scale == 8)
            {
                svalue = 3;
            }

            // scale
            encoder.AppendBits(svalue, 2);

            // index
            if (index == null)
            {
                encoder.Append3Bits(Bits.b100);
            }
            else
            {
                encoder.AppendRegister(index);
            }

            // base
            if (@base == null)
            {
                encoder.Append3Bits(Bits.b101);
            }
            else
            {
                encoder.AppendRegister(@base);
            }

            return(encoder);
        }
Beispiel #2
0
        public static OpcodeEncoder ModRegRMSIBDisplacement(this OpcodeEncoder encoder, Operand result, Operand op1, Operand op2)
        {
            if (op2.IsConstant)
            {
                encoder.AppendMod(true, op2);                               // 2:mod
                encoder.AppendRegister(result.Register);                    // 3:register (destination)
                encoder.AppendRM(op1);                                      // 3:r/m (source)
                encoder.AppendConditionalDisplacement(op2);                 // 8/32:displacement value
            }
            else
            {
                encoder.AppendMod(Bits.b00);                                        // 2:mod
                encoder.AppendRegister(result.Register);                            // 3:register (destination)
                encoder.AppendRM(Bits.b100);                                        // 3:r/m (source)
                encoder.AppendSIB(1, op2.Register, op1.Register);                   // 8:sib (scale, index, base)
            }

            return(encoder);
        }