【发布时间】:2015-04-23 01:06:42
【问题描述】:
编码 (ModRM:r/m, ModRM:reg) 与 (ModRM:reg, ModRM:r/m) 有什么区别?具体来说说像 CMPXCHG 与 DIVPD 这样的指令。我认为寄存器和地址总是在第一个字节中编码,然后如果需要,第二个字节中的 SIB 和位移?这是我的代码:
static void WriteRegisterToMemory(ICollection<Byte> bytes, IRegisterToMemoryInstruction instruction, Byte rex)
{
IAddress address = instruction.Address;
Byte register = instruction.Register;
if (address.NeedsRex)
{
rex |= 0x40;
if (address.RexB)
rex |= 1;
if (address.RexX)
rex |= 1 << 1;
}
if (register > 7)
rex |= 0x44; // REX.R
if (rex != 0)
bytes.Add(rex);
bytes.AddRange(instruction.Opcode);
Byte modRM = (Byte)((register % 8) << 3);
modRM |= address.GetModRMAddressByte();
bytes.Add(modRM);
address.WriteScaledIndexByteAndDisplacement(bytes);
}
所以这两条指令的编码完全相同,只是操作码不同? (英特尔 x64 手册第 457 页上的添加)
Op/En Operand 1 Operand 2
RM ModRM:reg (r, w) ModRM:r/m (r)
MR ModRM:r/m (r, w) ModRM:reg (r)
【问题讨论】:
标签: 64-bit machine-code