implement shr and ushr; teach add and sub about 32 bit immediate operands

This commit is contained in:
Joel Dice 2007-12-17 19:10:12 -07:00
parent 6895ffaa99
commit 3bafbf08bb

View File

@ -1122,12 +1122,19 @@ RegisterOperand::accept(Context* c, Operation operation,
switch (operation) {
case add: {
if (operand->value) {
assert(c, isInt8(operand->value)); // todo
rex(c);
c->code.append(0x83);
c->code.append(0xc0 | value);
c->code.append(operand->value);
if (isInt8(operand->value)) {
c->code.append(0x83);
c->code.append(0xc0 | value);
c->code.append(operand->value);
} else if (isInt32(operand->value)) {
c->code.append(0x81);
c->code.append(0xc0 | value);
c->code.append4(operand->value);
} else {
abort(c);
}
}
} break;
@ -1179,12 +1186,18 @@ RegisterOperand::accept(Context* c, Operation operation,
case sub: {
if (operand->value) {
assert(c, isInt8(operand->value)); // todo
rex(c);
c->code.append(0x83);
c->code.append(0xe8 | value);
c->code.append(operand->value);
if (isInt8(operand->value)) {
c->code.append(0x83);
c->code.append(0xe8 | value);
c->code.append(operand->value);
} else if (isInt32(operand->value)) {
c->code.append(0x81);
c->code.append(0xe8 | value);
c->code.append4(operand->value);
} else {
abort(c);
}
}
} break;
@ -1616,6 +1629,20 @@ MemoryOperand::accept(Context* c, Operation operation,
cx->release(c);
} break;
case shr: {
RegisterOperand* cx = temporary(c, rcx);
cx->accept(c, mov, operand);
encode(c, 0xd3, 5, this, true);
cx->release(c);
} break;
case ushr: {
RegisterOperand* cx = temporary(c, rcx);
cx->accept(c, mov, operand);
encode(c, 0xd3, 7, this, true);
cx->release(c);
} break;
case sub: {
encode(c, 0x29, operand->value, this, true);
} break;