64bit - x64 instruction encoding (r/m, reg vs reg, r/m) -
what's difference in encoding (modrm:r/m, modrm:reg) vs (modrm:reg, modrm:r/m)? instruction cmpxchg vs divpd. thought register , address encoded in first byte , sib , displacement in second byte if needed? here's code:
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); }
so these 2 instructions encoded same different opcodes? (adds on page 457 of intel x64 manual)
op/en operand 1 operand 2 rm modrm:reg (r, w) modrm:r/m (r) mr modrm:r/m (r, w) modrm:reg (r)
there isn't difference w.r.t. encoding, difference in 1 source , 1 destination. instructions have r/m
source, except things cmpxchg
, bts
, xadd
, xchg
ambiguous (it's symmetric), alu ops have r/m, r
form , r/m, imm
form, , mov's memory. in encoding instructions (even if both operands registers), careful "which way around" are, or might end operands swapped. that's all, there in end no difference in how encoded.