Commit 50552a0c authored by Marius Wachtler's avatar Marius Wachtler

assembler: fix cmp encoding

parent 3489a0aa
......@@ -940,17 +940,25 @@ void Assembler::cmp(Indirect mem, Register reg) {
assert(mem_idx >= 0 && mem_idx < 8);
assert(reg_idx >= 0 && reg_idx < 8);
bool needssib = (mem_idx == 0b100);
emitRex(rex);
emitByte(0x3B);
if (mem.offset == 0) {
emitModRM(0b00, reg_idx, mem_idx);
if (needssib)
emitSIB(0b00, 0b100, mem_idx);
} else if (-0x80 <= mem.offset && mem.offset < 0x80) {
emitModRM(0b01, reg_idx, mem_idx);
if (needssib)
emitSIB(0b00, 0b100, mem_idx);
emitByte(mem.offset);
} else {
assert(fitsInto<int32_t>(mem.offset));
emitModRM(0b10, reg_idx, mem_idx);
if (needssib)
emitSIB(0b00, 0b100, mem_idx);
emitInt(mem.offset, 4);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment