private static byte? CalculateModRM(byte? regField, Operand op1, Operand op2)
{
byte? modRM = null;
bool op1IsRegister = (op1 != null) && op1.IsCPURegister;
bool op2IsRegister = (op2 != null) && op2.IsCPURegister;
Debug.Assert(!(!op1IsRegister && op2IsRegister));
if (regField != null)
modRM = (byte)(regField.Value << 3);
if (op1IsRegister && op2IsRegister)
{
// mod = 11b, reg = rop1, r/m = rop2
modRM = (byte)((3 << 6) | (op1.Register.RegisterCode << 3) | op2.Register.RegisterCode);
}
else if (op1IsRegister)
{
modRM = (byte)(modRM.GetValueOrDefault() | (3 << 6) | op1.Register.RegisterCode);
}
return modRM;
}